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

Revision 41 of this benchmark created on


Description

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

Added case sensitivity to search

Setup

var str = 'INLINE-block(_ru.by_ruby)',
      arr = ['inline', 'inline-block', 'inline-table', 'ruby'],
      obj = {
        'inline': true,
        'inline-block': true,
        'inline-table': true,
        'ruby': true
      },
      findThis = /(inline|ruby)/gi;

Test runner

Ready to run.

Testing in
TestOps/sec
test
findThis.test(str);
ready
search
str.search(findThis) > -1;
ready
exec
findThis.exec(str);
ready
match()
str.match(findThis) > 0;
ready
indexOf()
str.indexOf(findThis) > -1;
ready
string search
str.search('inline') > -1 && str.search('ruby') > -1;
ready
string indexOf
str.indexOf('inline') > -1 && str.indexOf('ruby') > -1;
ready
string match
str.match('inline') > -1 && str.match('ruby') > -1;
ready

Revisions

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