String slice vs array lookup

JavaScript performance comparison

Test case created by Eben Packwood

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  ND = [[0,0],[1,0],[0,-1],[-1,0],[0,1],[1,-1],[-1,-1],[-1,1],[1,1]];
  ND2 = " 0 0 1 0 0-1-1 0 0 1 1-1-1-1-1 1 1 1";

};
</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
Array lookup
for (var x=0;x<9;x++){
    var y = ND[x];
}
pending…
String lookup
for (var x=0;x<9;x++){
    var y = ND2.slice(x*4,x*4+2);
}
pending…

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

Compare results of other browsers

0 Comments