Array.from vs Array for-loop vs Set - Sequential allocation

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Array.from Object
const count = 40
let a = Array.from({length: count}, (e, i)=> i)
a = Array.from({length: count}, (e, i)=> i)
ready
Array for-loop
const count = 40
let a = []
for (let i = 0; i <= count; i++) {
	a.push(i)
}
a = []
for (let i = 0; i <= count; i++) {
	a.push(i)
}

ready
Set
const count = 40
let a = new Set()
for (let i = 0; i <= count; i++) {
	a.add(i)
}
a.clear()
for (let i = 0; i <= count; i++) {
	a.add(i)
}
ready
Array.from.keys
const count = 40
let a = Array.from(Array(count).keys());
a = Array.from(Array(count).keys());

ready

Revisions

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