Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.136 Safari/537.36
Chrome 98
Windows
Desktop
3 years ago
Test name Executions per second
Array constructor - 100000 items 501.4 Ops/sec
Array literal - 100000 items 474.7 Ops/sec
Array literal (assign by index) - 100000 items 508.4 Ops/sec
Array literal (explicit length) - 100000 items 523.5 Ops/sec
Script Preparation code:
x
 
var n = 10000;
function Person(name, age) {
  this.name = name;
  this.age = age;
}
Tests:
  • Array constructor - 100000 items

     
    var arr = new Array(n);
    for (var i = 0; i < n; i++) {
      arr[i] = new Person(i + '', i);
    }
  • Array literal - 100000 items

     
    var arr = [];
    for (var i = 0; i < n; i++) {
      arr.push(new Person(i + '', i));
    } 
  • Array literal (assign by index) - 100000 items

     
    var arr = [];
    for (var i = 0; i < n; i++) {
      arr[i] = new Person(i + '', i);
    } 
  • Array literal (explicit length) - 100000 items

     
    var arr = [];
    arr.length = n;
    for (var i = 0; i < n; i++) {
      arr[i] = new Person(i + '', i);
    }