test vs indexof test (v5)

Revision 5 of this benchmark created on


Setup

var str1 = "foo.bar[car]",
        str2 = "foobarcar"
        re = /^[^[.]+$/,
        re2= /[[.]/;
    
    function check1(value) {
      return re.test(value);
    }
    
    function check2(value) {
      return value.indexOf('.') < 0 && value.indexOf('[') < 0;
    }
    
    function check3(value) {
      return !re2.test(value);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
test match
var r = check1(str1);
ready
indexOf match
var r = check2(str1);
ready
test miss
var r = check1(str2);
ready
indexOf miss
var r = check2(str2);
ready
test miss (alt)
var r = check3(str2);
ready

Revisions

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