plugin-endpoints icon indicating copy to clipboard operation
plugin-endpoints copied to clipboard

Adds regex comparison

Open javorszky opened this issue 9 years ago • 3 comments

Because sometimes you want to enable things on /category/, but not on /category/product/. /category/?$ will achieve that. All the declarations work as normal.

javorszky avatar Aug 10 '16 22:08 javorszky

I have no idea how to test this functionality besides clicking on things.

javorszky avatar Aug 10 '16 23:08 javorszky

Hi @javorszky,

While I love the idea of supporting regexes in routes, I'm thinking something along the lines of how NGINX does it (prefix that indicates a regex follows) would be better suited here.

This because the performance cost of a regex can really add up in scale. Here's a rough (relative) performance comparison:

10 endpoints, no match

  • stripos: 0.14 seconds
  • preg_match: 0.34 seconds

100 endpoints, no match

  • stripos: 0.19 seconds
  • preg_match: 1.1 seconds

1000 endpoints, no match

  • stripos: 0.73 seconds
  • preg_match: 7.84 seconds

I'll have a play with other options over the next few days to see what could be a good solution here. :)

PS. You can run these benchmarks yourself by running the newly added tests/benchmark.php file.

php tests/benchmark.php 1000

dannyvankooten avatar Aug 11 '16 13:08 dannyvankooten

Another option is to simply pull in nikic's FastRoute or my AltoRouter as then we'd have a very powerful router at a minimal performance cost, but it'll still be more complex and slower than a simple string comparison.

dannyvankooten avatar Aug 11 '16 13:08 dannyvankooten