For vs ForEach vs Map (v2)

Revision 2 of this benchmark created on


Setup

let data = [];

for (let i = 0; i < 1000000; i++){
	data.push(Math.floor(Math.random()*i+1000000));
}

Test runner

Ready to run.

Testing in
TestOps/sec
for
let sum = 0;
let _new = [];

for (let k = 0; k < data.length; k++){
	let v = data[k];
	sum += v;
	_new.push(v);
}
ready
forEach
let sum = 0;
let _new = [];

data.forEach((v) => {
	sum += v;
	_new.push(v);
});
ready
map
let sum = 0;
let _new = data.map((k,v)=>{
	sum += v;
	return v;
});
ready

Revisions

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