RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 45 of this test case created by

Preparation code

<script>
  var str = '<div class="chatbox">';
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var precompiledRegex = /data-hook/;

};
</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
test
/data-hook/.test(str);
pending…
search
str.search(/data-hook/) > -1;
pending…
match
str.match(/data-hook/).length > 0;
pending…
indexOf
str.indexOf(/data-hook/) > -1;
pending…
precompiled test
precompiledRegex.test(str);
pending…
precompiled search
str.search(precompiledRegex) > -1;
pending…
precompiled match
str.match(precompiledRegex).length > 0;
pending…
precompiled indexOf
str.indexOf(precompiledRegex) > -1;
pending…
indexOf string primitive
str.indexOf('data-hook') > -1;
pending…
split string into array
str.split('data-hook').length > 1
pending…
Compiled Regex and Test
var compiledRegex = /data-hook/;
compiledRegex.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