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

Revision 45 of this benchmark created on


Preparation HTML

<script>
  var str = '<div class="chatbox">';
</script>

Setup

var precompiledRegex = /data-hook/;

Test runner

Ready to run.

Testing in
TestOps/sec
test
/data-hook/.test(str);
ready
search
str.search(/data-hook/) > -1;
ready
match
str.match(/data-hook/).length > 0;
ready
indexOf
str.indexOf(/data-hook/) > -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('data-hook') > -1;
ready
split string into array
str.split('data-hook').length > 1
ready
Compiled Regex and Test
var compiledRegex = /data-hook/;
compiledRegex.test(str);
ready

Revisions

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