Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array constructor vs literal performance - 100000 items
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Array constructor - 100000 items
1483.8 Ops/sec
Array literal - 100000 items
1391.3 Ops/sec
Array literal (assign by index) - 100000 items
1450.7 Ops/sec
Array literal (explicit length) - 100000 items
1485.1 Ops/sec
Script Preparation code:
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); }