Closed roflmaostc closed 1 year ago
btime
inlines the computation for measuring repeated calls, while time
records the cost of the call occurring once. Both accurate measurements, but of different operations.
Hm, I'm confused :confused:
So @btime
does not calculate the same operation? Does it execute the for-loop or not?
Because @time
executes the for-loop (it scales linearly with N where @btime
doesn't)
julia> @btime $f(100_000_000) evals=1 samples=1
365.000 ns (0 allocations: 0 bytes)
5000000050000000
julia> @time f(100_000_000)
0.107526 seconds
5000000050000000
It take the call f(10)
and creates a new function g() = f(10)
and then benchmarks the call to g
.
Now N
is known to be constant and the compiler can optimize that.
Ah, got it! Thanks @vchuravy @vtjnash !
Hi,
the following example confuses me.
The compiler is able to reduce the function to the constant O(1) Gauss sum. But only when used with
@btime
. With@time
the runtime is dependent onN
.Why is that?