iterator.flat (v6)

Revision 6 of this benchmark created on


Setup

const arrays = Array.from({length: 100}, () => Array.from({length: 200_000}, (_, i) => i))

Test runner

Ready to run.

Testing in
TestOps/sec
push flat
const t = []
for (const array of arrays) {
	t.push(array)
}
t.flat()
ready
nested push
const r = []
for (const array of arrays) {
	for (const i of array) {
		r.push(i)
	}
}
ready
push spread
const chunkSize = 100_000
const r = []
for (const array of arrays) {
    for (let i = 0; i < array.length; i += chunkSize) {
      r.push(...array.slice(i, i + chunkSize));
    }
}
ready
spread flat
const r = [...arrays].flat()
ready
assign double spread
let r = []
for (const array of arrays) {
	r = [...r, ...array]
}
ready
assign concat
let r = []
for (const array of arrays) {
	r = r.concat(array)
}
ready

Revisions

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