RegExp test / search / match vs. indexOf (v13)

Revision 13 of this benchmark created by Sudheer on


Description

Testing for the existence of characters in a string using Regular Expressions test, search, and match compared to indexOf.

Preparation HTML

<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>

Setup

var precompiledRegex = /discover.com/i;

Test runner

Ready to run.

Testing in
TestOps/sec
test
/discover.com/i.test(str);
ready
search
str.search(/discover.com/i) > -1;
ready
match
str.match(/discover.com/i).length > 0;
ready
indexOf
str.indexOf(/discover.com/i) > -1;
ready
precompiled test
precompiledRegex.test(str);
ready

Revisions

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