push + shift vs unshift + pop

Benchmark created by Jonas Fischer on


Preparation HTML

<script>
  var a = [];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
push + shift
var i = 0;
while (i++ != 28) a.push(String.fromCharCode((Math.random() * 255) | 0, (Math.random() * 255) | 0));

var i = 0;
while (i++ != 28) a.shift();
ready
unshift + pop
var i = 0;
while (i++ != 28) a.unshift(String.fromCharCode((Math.random() * 255) | 0, (Math.random() * 255) | 0));

var i = 0;
while (i++ != 28) a.pop();
ready

Revisions

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

  • Revision 1: published by Jonas Fischer on