regexp .test() vs indexOf

JavaScript performance comparison

Revision 134 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
indexOf
url.indexOf("chrome") !== 0;
hashAlgorithm.indexOf("hmac") !== -1;
pending…
test()
!/^chrome/i.test(url);
/hmac/i.test(hashAlgorithm);
pending…
test() + brackets
!(/^chrome/i).test(url);
(/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