3 ms·
Repeating what I said on Reddit: The Regexp vs. indexOf test seems a little misleading. Generally, .indexOf will be faster, but they seem to have performed a ve
by TurplePurtle 15y ago
Repeating what I said on Reddit: The Regexp vs. indexOf test seems a little misleading. Generally, .indexOf will be faster, but they seem to have performed a very specific test that requires the indexOf method to do some string concatenation before actually searching, which IMO invalidates the usefulness of the test.
Please correct me if I'm wrong.
The test I'm talking about: http://jsperf.com/regexp-indexof-perf http://jsperf.com/regexp-indexof-perf
- jdd 15y agoThe point of this test is to show that you should avoid making blanket assumptions about performance and that you shouldn't fear the RegExp :) You can see my full reply here: http://jsperf.com/regexp-indexof-perf#comment-3 http://jsperf.com/regexp-indexof-perf#comment-3
- WayneDB 15y agoYou're still testing concat + indexOf, not just indexOf. I think that test is broken.
- jdd 15y agoThe test isn't broken in the scope of its use case. You are totally missing the point which is RegExp's are no longer a guaranteed fail when it comes to performance and that in many situations, including that jsPerf test, can out perform the indexOf equivalent.
- WayneDB 15y agoI think that a lot of people would just like to see a direct comparison, that's all.