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:
8 months ago
Test name
Executions per second
reduce.concat()
6945728.0 Ops/sec
flat()
3515275.8 Ops/sec
es-toolkit flatten()
9525598.0 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);