Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array.map() with spread vs for-loop
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/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Object.fromEntries with spread
154.1 Ops/sec
for-loop and object (reuse object)
7519.6 Ops/sec
for-loop and object (creating temporary objects)
54.1 Ops/sec
for-loop and map
848.7 Ops/sec
Script Preparation code:
var entries = Object.entries({ ...Array.from(Array(10000).keys()) });
Tests:
Object.fromEntries with spread
const obj = Object.fromEntries([ ...entries.map((key, value) => [key, value]) ]);
for-loop and object (reuse object)
const obj = {}; for (const [key, value] of entries) { obj[key] = value; }
for-loop and object (creating temporary objects)
let obj = {}; for (const [key, value] of entries) { obj = { ...obj, [key]: value }; }
for-loop and map
const map = new Map(); for (const [key, value] of entries) { map.set(key, value); } const obj = Object.fromEntries(map);