Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flat() vs reduce.concat() vs es-toolkit flatten()
(version: 1)
Comparing performance of:
reduce.concat() vs flat() vs es-toolkit flatten()
Created:
6 months ago
by:
Guest
Jump to the latest result
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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
reduce.concat()
flat()
es-toolkit flatten()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0
Browser/OS:
Firefox 144 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
reduce.concat()
13217549.0 Ops/sec
flat()
10864742.0 Ops/sec
es-toolkit flatten()
6456278.5 Ops/sec
Related benchmarks:
reduce.concat() vs flat(1) vs custom
Flatmap bruno
reduce.concat() vs flat() vs spread
reduce.concat() vs flat() v.2
reduce.concat() vs flat() vs [].concat(...arr)
reduce.concat() vs reduce + destructure vs flat()
Array.flat vs (reduce + concat) vs (reduce + destructure) vs (reduce + push)
reduce.concat() vs flat() vs concat(...)
flat() vs reduce.concat()
Comments
Confirm delete:
Do you really want to delete benchmark?