Test name | Executions per second |
---|---|
foreach | 157075.2 Ops/sec |
for-in | 88800.1 Ops/sec |
for-of | 160777.2 Ops/sec |
for | 198278.4 Ops/sec |
optimized-for | 212082.1 Ops/sec |
const items = Array.from({length: 10}, () => Math.floor(Math.random() * 40));
let index = 0;
items.forEach(i => index++);
const items = Array.from({length: 10}, () => Math.floor(Math.random() * 40));
let index = 0;
for (let i in items) {
index++;
}
const items = Array.from({length: 10}, () => Math.floor(Math.random() * 40));
let index = 0;
for (let i of items) {
index++;
}
const items = Array.from({length: 10}, () => Math.floor(Math.random() * 40));
let index = 0;
for(let i = 0; i < items.length; ++i) {
index++;
}
const items = Array.from({length: 10}, () => Math.floor(Math.random() * 40));
let index = 0;
for(let i = items.length; i > 0; --i) {
index++;
}