Ah, thanks for that!
I did put the gc() inside the @time intentionally, so that each test would
include the time to clean up after itself.
I still find it a bit tricky to reason about what can/can't be optimized,
but I'm getting better about writing performance tests so that if I make
changes
If you measure time using the @time macro instead of with tic()/toc(), you
also get information about memory allocation and garbage collection. Doing
that, I find
Timing with allocation each call
elapsed time: 0.004325641 seconds (4167824 bytes allocated)
Timing without allocation each call
Hi Thomas,
Thanks for the pointer towards @time and the GC info.
I also just realized I broke a golden performance rule in my test, which
was referencing variables in global scope.
Putting the whole test inside a function gives more reasonable results in
the sense that #2 and #4 do the exact
Mystery solved. In #3 I was missing the indexing `[i]` so I was adding a
constant to the whole array instead of just incrementing that item each
time.
My final results were (note I'm doing way more trials now to offset the GC
time):
```
Doing 10 Iterations of each...
---
Timing with