Push vs [i] (v4)

Revision 4 of this benchmark created by Jörg Schaper on


Description

is array.push(i) fast than array[i] = i ?

Setup

var $I = 12345;

Test runner

Ready to run.

Testing in
TestOps/sec
push
var I = $I, i = 0, A = [];
for( i; i < I; i++ ) A.push(i);
ready
[1]
var I = $I, i = 0, A = [];
for( i; i < I; i++ ) A[i] = i;
ready
[2]
var I = $I, i = 0, A = new Array(I);
for( i; i < I; i++ ) A[i] = i;
ready
[3]
var I = $I, i = 0, A = new Array(I);
for( i; i < I; A[i] = i++ ) ;
ready

Revisions

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