Array unshift() vs push() + reverse() (v10)

Revision 10 of this benchmark created by Bombo on


Description

Tests the performance difference of using two different ways of filling arrays at the start. The two TCs produce the same result. We need a lot of elements to see the real difference.

Test runner

Ready to run.

Testing in
TestOps/sec
unshift()
var a = [];

for (var i = 10000; i--;)
  a.unshift(i);

for (var i = 10000; i--;)
  a.pop();
ready
push() + reverse()
var a = [];

for (var i = 0; i++ < 10000;)
  a.push(i);

a.reverse();

for (var i = 10000; i--;)
  a.pop();
ready

Revisions

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