startsWith

JavaScript performance comparison

Revision 32 of this test case created by Alvaro

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  a = ["test"];
  for (var i = 0; i < 10000; i++) {
    a.push("some Other Stuff");
  }
  s = a.join();
  
  String.prototype.startsWithCharAt = function (pattern) {
        var length = pattern.length; 
        for (var i = 0; i < length; i++) {
          if (pattern.charAt(i) !== this.charAt(i)) return false;
        }
        return true;
  }

};
</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("not there") == 0);
pending…
lastIndexOf
r1 = (s.lastIndexOf("test", 0) == 0);
r2 = (s.lastIndexOf("not there", 0) == 0);
pending…
substring
r1 = (s.substring(0, "test".length) == "test");
r2 = (s.substring(0, "not there".length) == "not there");
pending…
slice
r1 = (s.slice(0, "test".length) == "test");
r2 = (s.slice(0, "not there".length) == "not there");
pending…
regex
r1 = (/^test/i).test(s);
r2 = (/^not there/i).test(s);
pending…
startsWithCharAt
r1 = s.startsWithCharAt("test");
r2 = s.startsWithCharAt("not there");
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