regexp .test() vs indexOf

JavaScript performance comparison

Revision 133 of this test case created

Info

regex.test() vs indexOf()

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var url = "https://www.google.ca/search?q=google+search+test&oq=google+search+test&aqs=chrome..69i57j0l5.4488j0j1&sourceid=chrome&es_sm=122&ie=UTF-8";
   
    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