regexp vs indexOf

JavaScript performance comparison

Revision 41 of this test case created by ariel

Info

I've increased the text size, since in real life scenarios you usually search for short patterns in a substancially longer text.

Preparation code

<script>
  var str = "hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test. hello world! This is a longer, albit fixed, text, with hello world! repeaded in it several time. The text itself is repeated by copy and paste, in hope that it will result in a better test.";
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Regexp
str.match(/world/);
pending…
indexOf
str.indexOf("world");
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment