RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 82 of this test case created by

Preparation code

<script>
  var str = '00000000-0000-1000-8080-808080808080';
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var precompiledRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

};
</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
precompiled indexOf
str.indexOf(precompiledRegex) > -1;
pending…
precompiled match
str.match(precompiledRegex).length > 0;
pending…
precompiled test
precompiledRegex.test(str);
pending…
precompiled search
str.search(precompiledRegex) > -1;
pending…
indexOf
str.indexOf(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) > -1;
pending…
search
str.search(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) > -1;
pending…
match
str.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i).length > 0;
pending…
test
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.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