Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
flat() vs reduce.concat() vs es-toolkit flatten()
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/141.0.0.0 Safari/537.36
Browser:
Chrome 141
Operating system:
Windows
Device Platform:
Desktop
Date tested:
10 months ago
es-toolkit flatten()
9.5M/s
reduce.concat()
6.9M/s
flat()
3.5M/s
View exact numbers
Test name
Executions per second
✓
es-toolkit flatten()
9,525,598 Ops/sec
reduce.concat()
6,945,728 Ops/sec
flat()
3,515,276 Ops/sec
Tests:
reduce.concat()
const params = [[ 1, 2], ["hello", true, 7]]; const other = params.reduce((acc, val) => acc.concat(val));
flat()
const params = [[1, 2], ["hello", true, 7]]; const other = params.flat();
es-toolkit flatten()
function flatten(arr, depth = 1) { const result = []; const flooredDepth = Math.floor(depth); const recursive = (arr, currentDepth) => { for (let i = 0; i < arr.length; i++) { const item = arr[i]; if (Array.isArray(item) && currentDepth < flooredDepth) { recursive(item, currentDepth + 1); } else { result.push(item); } } }; recursive(arr, 0); return result; } const params = [[ 1, 2], ["hello", true, 7]]; const other = flatten(params);