Array direct assignment vs push (v10)

Revision 10 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Direct assignment
var array = [],
    other_array = 0,
    count = 100,
    i;

for (i = 0; i < count; i++) {
  array[i] = Math.random();
}
ready
Push
var array = [],
    other_array = 0,
    count = 100,
    i;

for (i = 0; i < count; i++) {
  array.push(Math.random());
}
ready
Direct assignment (calculated)
var array = [],
    other_array = 0,
    count = 100,
    i;

for (i = 0; i < count; i++) {
  array[array.length] = Math.random();
}
ready
other
var array = [],
    other_array = 0,
    count = 100,
    i;

for (i = 0; i < count; i++) {
    array[other_array++] = Math.random();
}
ready
cache method
var array = [],
    other_array = 0,
    count = 100,
    i;

for (i = 0; i < count; i++) {
  array[i] = Math.random();
}
ready

Revisions

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