Test name | Executions per second |
---|---|
foreach | 68.6 Ops/sec |
for-in | 27.8 Ops/sec |
for-of | 77.6 Ops/sec |
for | 93.9 Ops/sec |
optimized-for | 94.4 Ops/sec |
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40));
let index = 0;
items.forEach(i => index++);
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40));
let index = 0;
for (let i in items) {
index++;
}
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40));
let index = 0;
for (let i of items) {
index++;
}
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40));
let index = 0;
for(let i = 0; i < items.length; ++i) {
index++;
}
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40));
let index = 0;
for(let i = items.length; i > 0; --i) {
index++;
}