pop vs shift on a array (v33)

Revision 33 of this benchmark created on


Description

If you can choose between a .pop() or .shift() on a Array, what would be a wise decision?

As my http://jsperf.com/adding-items-array/6 test shows the unshift is awful for performance. The same counts for .shift(), awful performance.

Setup

var array1 = new Array();
    for ( var j = 0; j < 2000; j++ ) array1.push(Math.random());
    var i = array1.length / 2;

Test runner

Ready to run.

Testing in
TestOps/sec
.pop()
while (i--) {
 array1.pop();
}
ready
.shift()
while (i--) {
 array1.shift();
}
ready
.splice beginning
while (i--) {
 array1.splice(0, 1);
}
ready
.splice end
while (i--) {
 array1.splice(i, 1);
}
ready
.splice chunk
array.splice(0, i);
ready

Revisions

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