Traversal perftest (v4)

Revision 4 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
map 10M
const a = new Array(10000000).fill(1)
let s = 0

a.map((n) => s += n)
console.log('map', s)
ready
generator 10M
let s = 0
const g = function*(arr, fn) {
	for(const item of arr) {
		yield(fn(item))
	}
}

for(const value of g(new Array(10000000).fill(1), (n) => s += n)) {
	
}

console.log('generator', s)
ready
forEach 10M
const a = new Array(10000000).fill(1)
let s = 0

a.forEach((n) => s += n)
console.log('forEach ', s)
ready
reduce 10M
const a = new Array(10000000).fill(1)
const s = a.reduce((acc, item) => acc + item, 0)
console.log('reduce', s)
ready
generator internalize 10M
let s = 0
const g = function*(arr, fn) {
	for(const item of arr) {
		fn(item)
	}
	yield(s)
}
g(new Array(10000000).fill(1), (n) => s += n).next()

console.log('generator', s)
ready

Revisions

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