starts_with (v12)

Revision 12 of this benchmark created on


Description

fastest starts-with string match

Setup

var arr = [],
        i, str = "abcdefghijklmnopqrstuvwxyz";
    
    for (i = 0; i < 1000000; i++) {
      arr.push(str.charAt(i % 26) + str);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
arr.filter(function(s) {
  return s.indexOf('abcdefghijkl') === 0;
});
ready
regexp
arr.filter(function(s) {
  return !!s.match(/^abcdefghijkl/);
});
ready
substring
arr.filter(function(s) {
  return s.substring(0, 12) === 'abcdefghijkl';
});
ready

Revisions

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