RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 13 of this test case created by Sudheer

Preparation code

<script>
  var str = 'collapsedContentLink;;http://ad.doubleclick.net/clk;260736037;45570551;f?http://ad.doubleclick.net/click;h=v2|3FEF|0|0|%2a|o;264355298;0-0;0;90019447;31-1|1;51059432|51029275|1%3B%3B;pc=DFP%eaid!%3fhttps://www.discover.com/credit-cards/cashback-bonus/cashback-calendar.html,expandedContentLink;;http://ad.doubleclick.net/clk;260736037;45570551;f?http://ad.doubleclick.net/click;h=v2|3FEF|0|0|%2a|o;264355298;0-0;0;90019447;31-1|1;51059432|51029275|1%3B%3B;pc=DFP%eaid!%3fhttps://www.discover.com/credit-cards/cashback-bonus/cashback-calendar.html,main;;http://ad.doubleclick.net/clk;260736037;45570551;f?http://ad.doubleclick.net/click;h=v2|3FEF|0|0|%2a|o;264355298;0-0;0;90019447;31-1|1;51059432|51029275|1%3B%3B;pc=DFP%eaid!%3fhttps://www.discover.com/credit-cards/cashback-bonus/cashback-calendar.html';
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var precompiledRegex = /discover.com/i;

};
</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
/discover.com/i.test(str);
pending…
search
str.search(/discover.com/i) > -1;
pending…
match
str.match(/discover.com/i).length > 0;
pending…
indexOf
str.indexOf(/discover.com/i) > -1;
pending…
precompiled test
precompiledRegex.test(str);
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