Map vs preallocation
Date tested:
3 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36
Test name
Executions per second
Map
63.0 Ops/sec
Preallocation
434.1 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var array = new Array(1000000).fill(0);
Tests:
Map
const array2 = array.map((item, index) => index);
Preallocation
const array2 = new Array(1000000).fill(0); for (let i = 0; i < array2.length; i++) array2[i] = i;
Open this result on MeasureThat.net