Array Assignment vs Array Push (v3)

Revision 3 of this benchmark created on


Description

You've heard the rumors - now here's the proof.

v3 adds pre-allocation

Setup

var size = 2000;

Test runner

Ready to run.

Testing in
TestOps/sec
arrayA[i] = 'foo';
var arrayA = [];
for (var i = 0; i < size; i++) {
  arrayA[i] = 'foo';
}
ready
arrayB.push('foo');
var arrayB = [];
for (var i = 0; i < size; i++) {
  arrayB.push('foo');
}
ready
arrayC[i] = 'foo'; (preallocated)
var arrayC = new Array(size);
for (var i = 0; i < size; i++) {
  arrayC[i] = 'foo';
}
ready

Revisions

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