regexp .test() vs indexOf

JavaScript performance comparison

Revision 132 of this test case created

Info

regex.test() vs indexOf()

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var url = "http://jsperf.com/regexp-vs-indexof/";
    var hashAlgorithm = "hmac-md5";
};
</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
indexOf1
url.indexOf("chrome") !== 0;
pending…
.test 1
!/^chrome/i.test(url);
pending…
.test 1 + brackets
!(/^chrome/i).test(url);
pending…
.indexOf 2
hashAlgorithm.indexOf("hmac") !== -1;
pending…
.test 2
/hmac/i.test(hashAlgorithm);
pending…
.text 2 + brackets
(/hmac/i).test(hashAlgorithm);
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