push/pop vs unshift/shift

JavaScript performance comparison

Test case created

Info

Comparing the speed / performance of using an array as a queue using either push & pop or unshift & shift. Tests are both raw, and with accessing the last added entry.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Push/Pop
var l = ['a', 'b', 'c', 'd'],
    e;
l.push('e');
e = l.pop();
pending…
Unshift/Shift
var l = ['b', 'c', 'd', 'e'],
    a;
l.unshift('a');
a = l.shift();
pending…
Push/Access/Pop
var l = ['a', 'b', 'c', 'd'],
    e, v;
l.push('e');
v = l[l.length];
e = l.pop();
pending…
Unshift/Access/Shift
var l = ['b', 'c', 'd', 'e'],
    a, v;
l.unshift('a');
v = l[0];
a = l.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