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

Revision 17 of this benchmark created 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/;

Test runner

Ready to run.

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

Revisions

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