Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Reduce + for of vs Map and nested for of
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/143.0.0.0 Safari/537.36
Browser:
Chrome 143
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
4 months ago
Test name
Executions per second
Reduce + for of
10526387.0 Ops/sec
Map, nested for of + Object.fromEntries
3553924.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const data = [ { fields: { internalName: "__NAME__", targetCategoryId: ["1", "2", "3", "4"], textColor: "#FFFFFF" }, }, { fields: { internalName: "__NAME__", targetCategoryId: ["1", "2", "3", "4"], textColor: "#FFFFFF" }, }, ];
Tests:
Reduce + for of
(() => { return data.reduce( (acc, cur) => { for (const id of cur.fields.targetCategoryId) { acc[id] = { textColor: cur.fields.textColor }; } return acc; }, {}, ); })();
Map, nested for of + Object.fromEntries
(() => { const configurationMap = new Map(); for (const configuration of data) { for (const id of configuration.fields.targetCategoryId) { configurationMap.set(id, { textColor: configuration.fields.textColor }); } } return Object.fromEntries(configurationMap); })();