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

Revision 85 of this benchmark created by tjaden 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 = /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.toLowerCase();
str.indexOf('iphone') > -1;
ready

Revisions

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