for vs map (v3)

Revision 3 of this benchmark created on


Setup

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

let x1 = new Array(a.length);
let x2 = [];
for (let i = 0; i < a.length; i++) {
	x2.push({});
}

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

Test runner

Ready to run.

Testing in
TestOps/sec
map
let x = a.map(mappedFn)
ready
for
let x = []
for (let i = 0; i < a.length; i++) {
	x.push(mappedFn(a[i]))
}
ready
for with capacity
for (let i = 0; i < a.length; i++) {
	x1[i] = mappedFn(a[i])
}
ready
for with capacity 2
for (let i = 0; i < a.length; i++) {
	x2[i] = mappedFn(a[i])
}
ready

Revisions

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