forEach vs map (v3)

Revision 3 of this benchmark created on


Setup

var arr = null;
var doubled = null;

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
arr = [1,2,3,4,5];
arr.forEach((num, index) => {
    return arr[index] = num * 2;
});
console.log(arr);
ready
map
arr = [1,2,3,4,5];
doubled = arr.map(num => {
    return num * 2;
});
console.log(doubled);
ready

Revisions

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