In Python, a convenient way to evaluate the performance of code is timeit
. In Julia we have @time
, but this has the disadvantage of only running a piece of code once, which means you need to execute it several times to get a good picture of code performance. Is there a better way to time code in Julia, more akin to Python's timeit
?
The package BenchmarkTools
has @benchmark
and @btime
which has a statistical way of determining the number of runs.
julia> A = rand(100,100);
julia> B = rand(100,100);
julia> using BenchmarkTools
julia> @benchmark A*B
BenchmarkTools.Trial:
memory estimate: 78.20 KiB
allocs estimate: 2
--------------
minimum time: 48.302 μs (0.00% GC)
median time: 72.015 μs (0.00% GC)
mean time: 74.314 μs (6.52% GC)
maximum time: 3.232 ms (95.17% GC)
--------------
samples: 10000
evals/sample: 1
julia> @btime A*B;
49.180 μs (2 allocations: 78.20 KiB)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With