RegExp test / search / match vs. indexOf / substr (v50)

Revision 50 of this benchmark created on


Description

Testing for the existence of characters in a string using Regular Expressions test, search, match and substr compared to indexOf.

Preparation HTML

<script>
  var str = 'Hello, world.', q = 'Hell', l = q.length;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
test
/Hell/.test(str);
ready
search
str.search(q) > -1;
ready
match
str.match(q).length > 0;
ready
indexOf
str.indexOf(q) === 0;
ready
substr
str.substr(0, l) === q;
ready
slice
str.slice(0, l) === q;
ready
lastIndexOf
str.lastIndexOf(q, 0) === 0;
ready

Revisions

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