JS for vs map vs push (v7)

Revision 7 of this benchmark created by bind vs partial on


Setup

var value = {
    v1: 1,
    v2: 2,
    v3: 3
  }
  var fields = [];
  var size = 25000;

Teardown



            fields = [];
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (var i = 0; i < size; i++) fields[i] = value;
ready
map
fields = Array.apply(null, new Array(size)).map(function() {
  return value;
});
ready
for with fixed size
fields = new Array(size);
for (var i = 0; i < size; i++) fields[i] = value;
ready
push
for (var i = 0; i < size; i++) fields.push(value);
ready
while
var i = 0;
while (i < size) {
  fields[i] = value;
  i++
}
ready
push and forEach
Array.apply(null, new Array(size)).forEach(function() {
  fields.push(value);
});
ready

Revisions

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