regexp vs indexOf (v65)

Revision 65 of this benchmark created by fgsfds on


Description

the further the string to match, the faster regexp is

Preparation HTML

<script>
  var s = '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',
 str = '', i = 1000, j;
 while (i--) str += s;
 str += "hello world!";
 s += "hello world!";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp
str.match('world');
ready
indexOf
str.indexOf('world');
ready
RegExp short
j = 1000;
while (j--) s.match('world');
ready
indexOf short
j = 1000;
while (j--) s.indexOf('world');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.