Skip to content

Conversation

facugon
Copy link

@facugon facugon commented Oct 21, 2023

No description provided.

@facugon
Copy link
Author

facugon commented Oct 21, 2023

Hi ,

Thank you for your work! It is exactly what I was looking for.

I was playing around with your benchmarks and I made a few changes in the map benchmarks in a way I think are fair comparison and I found out that using an initialized array in the for .. of gives very different results and I wanted to share the results of my discovery with you.

Perhaps using indexed arrays with a for .. of / for .. in add more lines of code and is kind of weird but the results are relevant.

I was unaware of the huge differences in performance of using initialized arrays against not using it.

My setup:

Ubuntu 20.04
Node 16.18.1

Regards

@facugon
Copy link
Author

facugon commented Oct 21, 2023

initialized array

Without

Benchmarking map:
Array.map x 33.02 ops/sec ±1.05% (57 runs sampled)
Array.map, destructuring x 33.27 ops/sec ±0.84% (58 runs sampled)
for of x 38.05 ops/sec ±10.96% (51 runs sampled)
for of, destructuring x 38.10 ops/sec ±11.71% (50 runs sampled)
for, init array x 70.51 ops/sec ±0.90% (72 runs sampled)
for, init array is faster

With

Benchmarking map:
Array.map x 33.43 ops/sec ±0.79% (58 runs sampled)
Array.map, destructuring x 32.79 ops/sec ±0.75% (57 runs sampled)
for of x 106 ops/sec ±0.48% (76 runs sampled)
for of, destructuring x 106 ops/sec ±0.56% (76 runs sampled)
for, init array x 68.66 ops/sec ±3.21% (71 runs sampled)
for of,for of, destructuring is faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant