startsWith

JavaScript performance comparison

Revision 54 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var TEST = 'test';
  var TEST2 = 'not there';
  
  var testReg = /^test/;
  var notThereReg = /^not there/;
  
  a = ["test"];
  for (var i = 0; i < 10000; i++) {
    a.push("some other stuff");
  }
  s = a.join();
  
  

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
indexOf
r1 = (s.indexOf(TEST) == 0);
r2 = (s.indexOf(TEST2) == 0);
pending…
lastIndexOf
r1 = (s.lastIndexOf(TEST, 0) == 0);
r2 = (s.lastIndexOf(TEST2, 0) == 0);
pending…
substring
r1 = (s.substring(0, TEST.length) == TEST);
r2 = (s.substring(0, TEST2.length) == TEST2);
pending…
slice
r1 = (s.slice(0, TEST.length) == TEST);
r2 = (s.slice(0, TEST2.length) == TEST2);
pending…
regex
r1 = (testReg).test(s);
r2 = (notThereReg).test(s);
pending…
strcmp
for (var i = 0; i < TEST.length; ++i) {
    if (s[i] !== TEST[i]) {break;}
}

for (i = 0; i < TEST2.length; ++i) {
    if (s[i] !== TEST2[i]) {break;}
}
pending…
charCodeAt
for (var i = 0; i < TEST.length; ++i) {
    if (s.charCodeAt(i) !== TEST.charCodeAt(i)) {break;}
}

for (i = 0; i < TEST2.length; ++i) {
    if (s.charCodeAt(i) !== TEST2.charCodeAt(i)) {break;}
}
pending…

Compare results of other browsers

Revisions

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

0 Comments