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

Revision 75 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 = 'Heya, Hiya, Hello, world.',
        q = 'Hell',
  qUpper = 'HELL',
        re = /hell/i;

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
test
/hell/i.test(str);
ready
search
str.toUpperCase().search(qUpper) > -1;
ready
match
str.match(q).length > 0;
ready
indexOf
str.toUpperCase().indexOf(qUpper) === 0;
ready
lastIndexOf
str.toUpperCase().lastIndexOf(qUpper, 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.