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; rv:143.0) Gecko/20100101 Firefox/143.0
Browser:
Firefox 143
Operating system:
Windows
Device Platform:
Desktop
Date tested:
8 months ago
Test name
Executions per second
reduce.concat()
11102455.0 Ops/sec
flat()
9012724.0 Ops/sec
es-toolkit flatten()
6041359.5 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);