Array.flat VS Array.reduce (v3)

Revision 3 of this benchmark created on


Setup

var arr = [
    Array.from(Array(100), (_,i) => i),
    Array.from(Array(100), (_,i) => 100 + i),
    Array.from(Array(100), (_,i) => 200 + i),
    Array.from(Array(100), (_,i) => 300 + i),
    Array.from(Array(100), (_,i) => 400 + i),
]

var size = 10000;
var res = []

Test runner

Ready to run.

Testing in
TestOps/sec
Array.flat
for(let i = 0; i < size; i++) {
	res = arr.flat()
}
ready
[...]
for(let i = 0; i < size; i++) {
	res = arr.reduce((acc, a) => [...acc, ...a])
}
ready

Revisions

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