shift vs pop

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var testArray = [];
    for (var i = 0, l = 4000; i < l; i++) {
        testArray.push( Math.round( Math.random() * l ) );
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
shift
var x = testArray.length;

do {
  var value = testArray.shift();
  console.log( value );
  x = testArray.length;
} while (x > 0);
pending…
pop
var x = testArray.length;

do {
  var value = testArray.pop();
  console.log( value );
  x = testArray.length;
} while (x > 0);
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

Add a comment