Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
String accumulation using forEach vs. map+join vs. reduce
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Browser:
Firefox 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
5 months ago
Test name
Executions per second
forEach
17499306.0 Ops/sec
map+join
1645113.1 Ops/sec
reduce
9403693.0 Ops/sec
Script Preparation code:
var property = "justify-content"; var value = ["space-around", "space-evenly"]; function normalizeDeclaration(property, value) { return property + ":" + value; }
Tests:
forEach
var cssText = ""; value.forEach((fallbackValue) => { cssText += "" + normalizeDeclaration(property, fallbackValue); }); var result = cssText.slice(1);
map+join
var result = value .map((fallbackValue) => normalizeDeclaration(property, fallbackValue)) .join(";");
reduce
var result = value.reduce( (accumulator, fallbackValue) => accumulator + ";" + normalizeDeclaration(property, fallbackValue), normalizeDeclaration(property, value[0]) );