pop vs shift on a array

JavaScript performance comparison

Revision 13 of this test case created

Info

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.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
.pop()
var array1 = new Array(2000);
var i = array1.length;
for (var j = 0; j < i; j++) array1[j] = {abc:1,eabefsa:2,ee:4,ff:['abc'],xx:12345,ole:{'asa':1}};
array1.reverse();
while (i--) {
 array1.pop();
}
pending…
.shift()
var array1 = new Array(2000);
var i = array1.length;
for (var j = 0; j < i; j++) array1[j] = {abc:1,eabefsa:2,ee:4,ff:['abc'],xx:12345,ole:{'asa':1}};
while (i--) {
 array1.shift();
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment