On node 16, I got
for i:
60 595 ops/s, ±12.74% | fastest
for of:
50 041 ops/s, ±0.22% | 17.42% slower
for each:
35 661 ops/s, ±17.08% | slowest, 41.15% slower
On Thursday, August 18, 2022 at 8:01:53 PM UTC+5:30 Avin Kavish wrote:
> 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' }),
> )
>
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/v8-dev/5466f319-db70-474f-842e-6ed414cfd423n%40googlegroups.com.