map is slow (v4)

Revision 4 of this benchmark created on


Setup

let a = new Array(20)
for (let i = 0; i < a.length; i++) {
	a[i] = (i + 10) * (i + 2)
}

function mappedFn(n) {
	return { 
		type: 'div', 
		children: ['item' + n]
	}
}

function map1(list, fn) {
	let x = []
	for (let i = 0; i < list.length; i++) {
		x.push(fn(list[i]))
	}
	return x	
}

function map2(list, fn) {
	let x = new Array(list.length)
	for (let i = 0; i < list.length; i++) {
		x[i] = fn(list[i])
	}
	return x	
}

Test runner

Ready to run.

Testing in
TestOps/sec
map
a.map(mappedFn)
ready
for
map1(a, mappedFn)
ready
capacity
map2(a, mappedFn)
ready

Revisions

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