Hello,
Not sure if I should be asking on the node.js repo, thought since it was a built in, must be related here. Array iteration using it's iterator seems to be about 17% slower than indexed access. Not sure if it's to do with this particular benchmark, I used an array with 10k elements. Here's my source code,
import b from 'benny'
const testData = Array.from({ length: 10_000 }, () => new Object())
let x, y, z
b.suite(
'iteration',
b.add('for i', () => {
for (let i = 0; i < testData.length; i++) {
x = testData[i]
}
}),
b.add('for of', () => {
for (let testDatum of testData) {
y = testDatum
}
}),
b.add('for each', () => {
testData.forEach((value, index) => {
z = value
})
}),
b.cycle(),
b.complete(),
b.save({ file: 'array-iteration', version: '1.0.0' }),
b.save({ file: 'array-iteration', format: 'chart.html' }),
)