flatMap vs flat+map vs concat

Benchmark created on


Setup

const ARR = Array.from(
	{length: 1000},
	() => ({
		arr: Array.from(
			{length: 100},
			(_, i) => i
		),
	})
)

Test runner

Ready to run.

Testing in
TestOps/sec
flatMap
ARR.flatMap(x => x.arr)
ready
flat+map
ARR.map(x => x.arr).flat()
ready
concat - literal
[].concat(...ARR.map(x => x.arr))
ready
concat - new
new Array().concat(...ARR.map(x => x.arr))
ready
concat prototype hack
Array.prototype.concat(...ARR.map(x => x.arr))
ready

Revisions

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