RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 85 of this test case created by tjaden

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 = /iPhone/;
</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
(/iPhone/i).test(str);
pending…
search
str.search(precompiledRegex) > -1;
pending…
match
str.match(precompiledRegex).length > 0;
pending…
indexOf
str.indexOf('iphone') > -1 || str.indexOf('iPhone') > -1;
pending…
indexOf - 2
str.toLowerCase();
str.indexOf('iphone') > -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