Array.from vs Array for-loop vs Set - Sequential allocation, shift, and by-value deletion (v4)

Revision 4 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Set
// allocation and reallocation
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)
}

//shift
let firstValue = a.values().next().value
a.delete(firstValue)
firstValue = a.values().next().value
a.delete(firstValue)

// by-value deletion
a.delete(30)
a.delete(40)
ready
Array for-loop
// allocation and reallocation
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)
}

//shift
a.shift()
a.shift()

// by-value deletion
a.splice(a.indexOf(30), 1)
a.splice(a.indexOf(40), 1)
ready

Revisions

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