re: How CloudFlare could have avoided its outage (maybe) VIEW POST

re: Great article Remy! It's absolutely absurd how slow regex is! 😅 e.g. Even the simplest of matches are left in the dust.


One remark though on your benchmark, I think that compile time of regexes is not excluded from the timing, which would be fair as if done correctly it will only impact the first execution of your code.

I'm saying that but I'm totally unsure of how JS handles this :)


Oh that's a really good point! I'll check that out.

So I added a few new tests:

  1. String.match() *
  2. RegExp.exec()
  3. RegExp.exec() *

*The RegExp instance is declared outside the test loop.

I'm seeing that #1 is significantly faster than the String.match() test where the regular expression is provided inline. The difference seems to be (very roughly) in the magnitude of ‭4,769,893‬ ops/sec.

The difference between #2 and #3 is significantly smaller and in favor of the inline test. The (very) rough difference seems to be around ‭121,562‬ ops/sec.

So, perhaps the String.match() method has some optimizations for handling inline regular expressions that aren't bogged down by the usage of an explicit RegExp instance.

code of conduct - report abuse