Arrays: map vs forEach

Benchmark created on


Setup

var input = [0,1,2,3,4,5,6,7,8,9];

Test runner

Ready to run.

Testing in
TestOps/sec
map
var output = input.map(v => {
	return v * v;
});
ready
forEach with push
var output = [];
input.forEach(v => {
	return output.push(v * v);
});
ready
forEach with index
var output = [];
input.forEach((v, idx) => {
	return output[idx] = v * v;
});
ready

Revisions

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