push/pop vs unshift/shift

JavaScript performance comparison

Revision 5 of this test case created by

Preparation code

<script>
  var pl = ['a', 'b', 'c', 'd'];
  var sl = ['b', 'c', 'd', 'e'];
  
  var e, a, v;
</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
Push/Pop
pl.push('e');
e = pl.pop();
pending…
Unshift/Shift
sl.unshift('a');
a = sl.shift();
pending…
Push/Access/Pop
pl.push('e');
v = pl[pl.length];
e = pl.pop();
pending…
Unshift/Access/Shift
sl.unshift('a');
v = sl[0];
a = sl.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.

1 Comment

Anonymous commented :

Push/Access/Pop is actually doing Push/Push/Access/Pop, because pl.length is beyond the end of the array.