Adding items to array

Benchmark created on


Description

Various of ways to add items to an array

Test runner

Ready to run.

Testing in
TestOps/sec
Native push
var a = [];
for (var i = 0; i < 200; i++) {
 a.push(i);
};
ready
Native unshift
var a = [];
for (var i = 0; i < 200; i++) {
 a.unshift(i);
};
ready
length
var a = [];
for (var i = 0; i < 200; i++) {
 a[a.length] = i;
};
ready
Cached length
var a = [],
    length = 0;
for (var i = 0; i < 200; i++) {
 a[length++] = i;
};
ready

Revisions

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