map-vs-foreach-speed-test

Benchmark created by cjaramillo on


Setup

let arr = [];
  for (var i=0; i<10000; i++, arr.push(i));

Test runner

Ready to run.

Testing in
TestOps/sec
Map
let doubled = arr.map(num => {
	return num * 2;
});
ready
ForEach
arr.forEach((num, index)=> {
	return arr[index] = num * 2;
});
ready

Revisions

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

  • Revision 1: published by cjaramillo on