Lodash flatten vs Array.flat vs reduce/concat (module import) (v2)

Revision 2 of this benchmark created on


Description

Lodash import using <script type="module">.

Preparation HTML

<script type="module">
const {flatten} = await import ("https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js");

window.flatten = flatten;
</script>

Setup

const arr = [0, 1, 2, [3, 4]];

const reduceFlatten = (a) =>  a.reduce((flat, next) => flat.concat(next), []);

Test runner

Ready to run.

Testing in
TestOps/sec
Lodash flatten
flatten(arr);
ready
Array.flat()
arr.flat();
ready
Reduce flatten
reduceFlatten(arr);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.