For Vs Each Vs Map

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
For
const array = [1, 2, 3, 4, 5];
let sum = 0;
for (let i = 0; i < array.length; i++) {
  sum += array[i];
}
ready
Each
const array = [1, 2, 3, 4, 5];
let sum = 0;
array.forEach(item => {
  sum += item;
});
ready
Map
const array = [1, 2, 3, 4, 5];
const sum = array.map(item => item).reduce((a, b) => a + b, 0);
ready

Revisions

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