Test name | Executions per second |
---|---|
foreach | 6.5 Ops/sec |
for-in | 3.6 Ops/sec |
for-of | 7.1 Ops/sec |
for | 4.7 Ops/sec |
const items = Array.from({length: 500000}, () => Math.floor(Math.random() * 40));
let index = 0;
items.forEach(i => index++);
const items = Array.from({length: 500000}, () => Math.floor(Math.random() * 40));
let index = 0;
for (let i in items) {
item = items[i]
index++;
}
const items = Array.from({length: 500000}, () => Math.floor(Math.random() * 40));
let index = 0;
for (let i of items) {
index++;
}
const items = Array.from({length: 500000}, () => Math.floor(Math.random() * 40));
let index = 0;
for(let i = 0; i < items.length; ++i) {
item = items[i]
index++;
}