regexp .test() vs indexOf

JavaScript performance comparison

Revision 137 of this test case created

Info

regex.test() vs indexOf()

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var url = Array(200).join("jsperf.com/regexp-vs-indexof/chrome")
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
indexOf + string
url.indexOf("chrome") !== 0;
url.indexOf("chrome") !== -1;
pending…
.search + regex
url.search(/^chrome/i) === -1;
url.search(/chrome/i) !== -1;
pending…
.test
!/^chrome/i.test(url);
/chrome/i.test(url);
pending…
.test + brackets
!(/^chrome/i).test(url);
(/chrome/i).test(url);
pending…
.search + string
url.search("chrome") !== 0;
url.search("chrome") !== -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. Here’s a list of current revisions for this page:

0 comments

Add a comment