RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 91 of this test case created by

Preparation code

<script>
var str = 'mozilla/5.0 (iphone; cpu iphone os 7_0 like mac os x; en-us) applewebkit/537.51.1 (khtml, like gecko) version/7.0 mobile/11a465 safari/9537.53';
var precompiledRegex = /;/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
test
(/;/i).test(str);
pending…
search
str.search(precompiledRegex) > -1;
pending…
match
str.match(precompiledRegex).length > 0;
pending…
for-loop
for (var i=0,l=str.length-1; i<l; ++i) {
   if (str.charCodeAt(i) === "59")
      break;
}
pending…
indexOf - 2
str.indexOf(';') > -1;
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