Perhaps to do with compiling the first time for the first run? Though from what I understand this TTFX is dealt with in 1.9x. Have you tried using BenchmarkTools? See here: Home · BenchmarkTools.jl
running on 1.9 without the @time macro it is instant (or at least not a few seconds).
confirmed.
It is also same with 1.8.5, with no ‘@time’ macro, it is instant, too.
I don’t understand @code_llvm f() things, but even to me, it looks like @time macro in later version does not allow optimized behavior.
There have been changes to @time since 1.7 to prevent the compiler from beating benachmarks in certain situations, so in 1.7 the loop isn’t actually executed but replaced with the return value by LLVM.
I don’t think this is correct. What’s actually happening is that @time appears to inhibit normal optimisation on 1.9. You can see that on all versions of Julia, the compiler figures out the analytical solution to the problem. Yet somehow, @time makes it slow in Julia 1.9.
Actually, #47561 was opened almost 5 months ago with the same sample code by the writer of the book “Julia for Data Analysis”, from which I got sample code in this question.