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

Revision 74 of this benchmark created by test 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

Revisions

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