Simple For Loops and Speed

It’s not that your code is slow, it’s that your benchmarking is slow. When you do the timing in global scope with non-const variables, Julia cannot be certain of the types, and cannot compile efficient code.

This is why using BenchmarkTools is a good idea. I never do any benchmarking with @time, only with @btime from BenchmarkTools. It takes care of everything for you.

2 Likes