starts_with (v16)

Revision 16 of this benchmark created on


Description

fastest starts-with string match

Setup

var str = "abcdefghijklmnopqrstuvwxyz";
    var begin1 = "abcde";
    var begin2 = "zyxwv;

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
return str.indexOf(begin1) == 0 && str.indexOf(begin2) == 0;
ready
regexp
var re1 = new RegExp("^" + begin1);
var re2 = new RegExp("^" + begin2);
return !!str.match(re1) && !! str.match(re2);
ready
substring
return (str.substring(0, begin1.length) == begin1) &&
  (str.substring(0, begin2.length) == begin2);
ready

Revisions

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