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 (X11; Ubuntu; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0
Browser:
Firefox 144
Operating system:
Ubuntu
Device Platform:
Desktop
Date tested:
5 months ago
Test name
Executions per second
reduce.concat()
13217549.0 Ops/sec
flat()
10864742.0 Ops/sec
es-toolkit flatten()
6456278.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);