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

Revision 90 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 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53';
var strLower = 'mozilla/5.0 (iphone; cpu iphone os 7_0 like mac os x; en-us) applewebkit/537.51.1 (khtml, like gecko) version/7.0 mobile/11a465 safari/9537.53';
var precompiledRegex = /iPhone/;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
test
(/iPhone/i).test(str);
ready
search
str.search(precompiledRegex) > -1;
ready
match
str.match(precompiledRegex).length > 0;
ready
indexOf
str.indexOf('iphone') > -1 || str.indexOf('iPhone') > -1;
ready
indexOf - 2
str.indexOf('iphone') > -1;
ready

Revisions

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