I struggle to understand the following behaviour of Julia’s compilation process: according to the @time
output, the sum of squares function defined below is not compiled when called with a constant argument.
I wonder what exactly is going on here.
julia> Σsquares(n) = let s=0
for i in 1:n
s += i*i
end
s
end
Σsquares (generic function with 1 method)
julia> const n = 1_000_000
1000000
julia> @time Σsquares(n)
0.000000 seconds
333333833333500000
julia> @time Σsquares(10n)
0.000000 seconds
1291990006563070912
julia> @time Σsquares(100n)
0.000001 seconds
672921401752298880
julia> k = 1_000_000
1000000
julia> @time Σsquares(k)
0.004474 seconds (143 allocations: 6.984 KiB, 99.68% compilation time)
333333833333500000