Zero filled array creation (v35)

Revision 35 of this benchmark created on


Description

Creating an array filled with zeros. Which is the fastest method? These methods are useful for arrays filled with a single element, except for the typed array conversion which works only with zeros. Only the first two methods are useful with incremental values or callbacks.

Test runner

Ready to run.

Testing in
TestOps/sec
Array push
for (var i = 0, a = []; i < 100; i++) a.push(0);
ready
Array assign
for (var i = 0, a = new Array(100); i < 100;) a[i++] = 0;
ready
Typed array conversion
[].slice.call(new Uint8Array(100));
ready
Binary concatenation
for (var i = 100, a = [], add = [0]; i; i >>=1) {
    if (i & 1) a.push.apply(a, add);
    add.push.apply(add, add);
}
ready
Array Apply
Array.apply(null, new Array(100)).map(Number.prototype.valueOf,0);
ready
while
var i=100, a = [];
while(i--){
  a[i] = 0;
}
ready
while_new
var i=100, a = new Array(100);
while(i--){
  a[i] = 0;
}
ready
Array assign create
var a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
ready
Array fill
var a = Array(100).fill(0);
ready

Revisions

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