RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 102 of this test case created by Eliseu Monar dos Santos

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var precompiledRegex = new RegExp("pretty"),
                   str = 'The common way of building UI is to first render your template, but then wire up events between your model and the DOM so when a particular property on your model changes, you can get a specific piece of the DOM (e.g. via jQuery) and update some property on it or it\'s contents. This works for small projects, but there\'s a performance penalty for doing this sort of thing lots of times in a single frame of execution since querying and updating the DOM are pretty expensive operations. It also tends to produce tons of boilerplate code.';

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
search
~str.search(/pretty/);
pending…
match
str.match(/pretty/);
pending…
precompiled test
precompiledRegex.test(str);
pending…
indexOf
~str.indexOf(/pretty/);
pending…
precompiled search
~str.search(precompiledRegex);
pending…
precompiled match
str.match(precompiledRegex);
pending…
precompiled indexOf
~str.indexOf(precompiledRegex);
pending…
test
/pretty/.test(str);
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.

0 Comments