Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reduce vs for-loop for typeAttributes
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/147.0.0.0 Safari/537.36
Browser:
Chrome 147
Operating system:
Windows
Device Platform:
Desktop
Date tested:
19 days ago
Test name
Executions per second
reduce
581104.5 Ops/sec
for-loop
545714.7 Ops/sec
Script Preparation code:
function getTypeAttributes() { return [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ]; } const o = {}; for (let i = 0, { length } = getTypeAttributes(); i < length; i += 1) { o[`typeAttribute${i}`] = `${i}`; } function typeAttributesWithReduce() { const typeAttributes = getTypeAttributes(); if (Array.isArray(typeAttributes)) { return typeAttributes.reduce((seed, attrName, index) => { seed[attrName] = o[`typeAttribute${index}`]; return seed; }, {}); } return {}; } function typeAttributesWithForLoop() { const typeAttributes = getTypeAttributes(); const attrs = {}; if (Array.isArray(typeAttributes)) { for (let i = 0, { length } = typeAttributes; i < length; i += 1) { attrs[typeAttributes[i]] = o[`typeAttribute${i}`]; } } return attrs; }
Tests:
reduce
typeAttributesWithReduce();
for-loop
typeAttributesWithForLoop();