test-loop-vs-map

Benchmark created on


Setup

let array = [Array(100_000).keys()].map((_, i) => {
	return {
		id: i,
	};
});

Test runner

Ready to run.

Testing in
TestOps/sec
map loop
array.map((obj) => {
	obj.id++;
	return obj;
});
ready
for loop
for (let i = 0; i < array.length; i++) {
	array[i].id++;
}
ready
for of loop
for (let obj of array) {
	obj.id++;
}
ready
map outside func
function transform(obj) {
	obj.id++;
	return obj;
}
array.map(transform);
ready

Revisions

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