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);
    } 
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Array constructor - 100000 items
    Array literal - 100000 items
    Array literal (assign by index) - 100000 items
    Array literal (explicit length) - 100000 items

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 18 days ago)
Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0
Firefox 133 on Linux
View result in a separate tab
Test name Executions per second
Array constructor - 100000 items 2994.9 Ops/sec
Array literal - 100000 items 2796.7 Ops/sec
Array literal (assign by index) - 100000 items 2794.0 Ops/sec
Array literal (explicit length) - 100000 items 2857.3 Ops/sec