shift vs index

JavaScript performance comparison

Test case created by randing89

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function newMatrix() {
    const matrix = [];
    for(let i = 0; i < 1000; i++){
      for(let j = 0; j < 1000; j++){
        matrix[i] = matrix[i] || [];
        matrix[i][j] = i + j;
      }
    }
    return matrix;
  }
  

};
</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
shift
const matrix = newMatrix();
let sum = 0;
while(matrix.length > 0) {
  sum += matrix[0][0];
  matrix.shift();
}
pending…
index access
const matrix = newMatrix();
let sum = 0;
for (let i = 0; i < matrix.length; i++) {
  sum += matrix[i][0];
}
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