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

Revision 54 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,
        re = /Hell/i;

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
test
/Hell/i.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
precompiled test
re.test(str);
ready
precomiled search
str.search(re) !== -1;
ready
precompiled exec
re.exec(str) !== null
ready

Revisions

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