Array vs Set (v5)

Revision 5 of this benchmark created on


Setup

const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
const s = new Set(a)

Test runner

Ready to run.

Testing in
TestOps/sec
Array forEach
let i = 0

a.forEach(val => {
	i += val
})
ready
Set forEach
let i = 0

s.forEach(val => {
	i += val
})
ready
Array for of
let i = 0

for (const val of a) {
	i += val
}
ready
Set for of
let i = 0

for (const val of s) {
	i += val
}
ready
Array for
let i = 0

for (let n = a.length - 1; n; --n) {
	i += a[n]
}
ready

Revisions

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