Queue: push/unshift vs. shift/pop vs. two push/pop stacks

JavaScript performance comparison

Test case created by Sean Silva

Preparation code

<script>
  var i;
  var arr = [];
  var supp_ary = [];
</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
unshift/pop
for (i = 0; i < 100; i++) {
 arr.unshift(i);
}

while (i--) arr.pop();
pending…
push/shift
for (i = 0; i < 100; i++) {
 arr.push(i);
}

while (i--) arr.shift();
pending…
two stacks
for (i = 0; i < 100; i++) {
 arr.push(i);
}

while (i--) supp_ary.push(arr.pop());
i = 100;
while (i--) supp_ary.pop();
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.

0 Comments