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

Revision 19 of this benchmark created on


Preparation HTML

<script>
  var str = 'inline-block';
</script>

Setup

var precompiledRegex = /(inline|ruby)/;

Test runner

Ready to run.

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

Revisions

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