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

Revision 46 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.

Setup

var str1 = 'key';
    var str2 = 'key,value';
    var str3 = 'key:value';

Test runner

Ready to run.

Testing in
TestOps/sec
test
/[,:]/.test(str1);
/[,:]/.test(str2);
/[,:]/.test(str3);
ready
search
str1.search(/[,:]/);
str2.search(/[,:]/);
str3.search(/[,:]/);
ready
indexOf
~str1.indexOf(',') || ~str1.indexOf(':');
~str2.indexOf(',') || ~str2.indexOf(':');
~str3.indexOf(',') || ~str3.indexOf(':');
ready

Revisions

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