3 ms·
This indicates it probably wont be much faster in JS http://jsperf.com/regex-list-vs-full http://jsperf.com/regex-list-vs-full Most of the time in the single-
by spion 12y ago
This indicates it probably wont be much faster in JS
http://jsperf.com/regex-list-vs-full http://jsperf.com/regex-list-vs-full
Most of the time in the single-regex case is likely spent on allocating the matches array (which for a router with 300 routes would have over 300 undefined elements on every execution)
V8 is not quite the typical dynamic language runtime. Code that would be dead slow in others is optimized really well by the amazing JIT.
- andrewvc 12y agoInteresting, I'm looking at it right now, and it's saying that the multiple regexes are ~ 50% slower in both chrome and firefox. Am I missing something? It looks like the single regex actually is a significant win. It is interesting how much allocation changes things though, very cool that you made this.
- spion 12y agoYeah multiple regexes are slower, but the performance gain isn't too gigantic. If we had `regex.execIterable(string)` we could avoid allocating massive arrays and maybe get a really significant difference