The tools described in this chapter, particularly the @time
macro, are useful to identify and investigate bottlenecks in our program. However, they are not very accurate for a fine-grained analysis of fast programs. If you want to, for example, compare two functions that take a few milliseconds to run, the amount of error and variability in the measurement will easily swamp the running time of this function.
The solution then is to use the Benchmarks.jl
package for statistically accurate benchmarking. This package is not yet published in the official repository, but is stable and high-quality nevertheless. It can be installed with Pkg.clone("https://github.com/johnmyleswhite/Benchmarks.jl.git")
and the subsequent usage is simple. Instead of using @time
, as before, simply use @benchmark
. Unlike @time
however, this macro can only be used in front of function calls, rather than any expression. It will evaluate the parameters of the function...