Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
add fields to objects in array
speed of different variants of adding field into objects in array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
map
862105.4 Ops/sec
forEach
1175064.9 Ops/sec
for of
1186947.0 Ops/sec
Script Preparation code:
var objects = [{ a: 'Ghkfj', b: 'Yvtzq', c: 'Rwsde' }, { a: 'Bpqwm', b: 'Sdfgh', c: 'Zxcvb' }, { a: 'Olmnp', b: 'Iujkl', c: 'Qwerty' }, { a: 'Cdsaf', b: 'Asdfg', c: 'Xcvbn' }, { a: 'Qwerz', b: 'Cvbnm', c: 'Xcvbn' } ];
Tests:
map
objects = objects.map(el => ({ ...el, d: Math.random() }));
forEach
objects.forEach(el => el.d = Math.random());
for of
for (let el of objects) el.d = Math.random();