indexOf === 0 vs RegExp/^/ (v3)

Revision 3 of this benchmark created on


Setup

var str1 = ":first-of-type";
    var str2 = "[attr]";

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp (exists)
var match = str1.search(/^:/) === 0;
ready
indexOf (exists)
var match = str1.indexOf(":") === 0;
ready
RegExp (doesn't exist)
var match = str2.search(/^:/) === 0;
ready
indexOf (doesn't exist)
var match = str2.indexOf(":") === 0;
ready

Revisions

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