Test name | Executions per second |
---|---|
for | 13433.7 Ops/sec |
for each | 60055.6 Ops/sec |
forEach | 726580.5 Ops/sec |
var array = new Array(1000);
for (var i = 0; i < array.length; i++) {
array[i] = i;
}
let sum = 0;
for (var i = 0; i < array.length; i++) {
sum += array[i];
}
let sum = 0;
for (var item in array) {
sum += item;
}
let sum = 0;
array.forEach(function(item, index) {
sum += item;
});