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

Revision 91 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 precompiledRegex = /;/i;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
test
(/;/i).test(str);
ready
search
str.search(precompiledRegex) > -1;
ready
match
str.match(precompiledRegex).length > 0;
ready
for-loop
for (var i=0,l=str.length-1; i<l; ++i) {
   if (str.charCodeAt(i) === "59")
      break;
}
ready
indexOf - 2
str.indexOf(';') > -1;
ready

Revisions

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