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

Revision 99 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 = 'inline-block';
</script>

Setup

var precompiledRegex = /inline/;

Test runner

Ready to run.

Testing in
TestOps/sec
test
/inline/.test(str);
ready
search
str.search(/inline/) > -1;
ready
match
str.match(/inline/);
ready
indexOf
str.indexOf(/inline/) > -1;
ready
precompiled test
precompiledRegex.test(str);
ready
precompiled search
str.search(precompiledRegex) > -1;
ready
precompiled match
str.match(precompiledRegex);
ready
precompiled indexOf
str.indexOf(precompiledRegex) > -1;
ready
indexOf string primitive
str.indexOf('inline') > -1;
ready
Primitive comparison
str === "inline" || str === "inline-block" || str === "inline-table" || str === "ruby";
ready

Revisions

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