You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-6Lines changed: 26 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,14 +31,34 @@ If you're benchmarking on Linux, I wrote up a series of [tips and tricks](https:
31
31
32
32
## Quick Start
33
33
34
-
The simplest usage is via the [`@btime` macro](https://github.com/JuliaCI/BenchmarkTools.jl/blob/master/doc/manual.md#benchmarking-basics), which is analogous to Julia's built-in [`@time` macro](https://docs.julialang.org/en/stable/stdlib/base/#Base.@time) but is often more accurate (by collecting results over multiple runs):
34
+
The primary macro provided by BenchmarkToolsis `@benchmark`:
35
35
36
36
```julia
37
37
julia>using BenchmarkTools
38
38
39
-
julia>@btimesin(1)
40
-
15.081 ns (0 allocations:0 bytes)
41
-
0.8414709848078965
39
+
# The `setup` expression is run once per sample, and is not included in the
40
+
# timing results. Note that each sample can require multiple evaluations
41
+
# benchmark kernel evaluations. See the BenchmarkTools manual for details.
42
+
julia>@benchmarksin(x) setup=(x=rand())
43
+
BenchmarkTools.Trial:
44
+
memory estimate:0 bytes
45
+
allocs estimate:0
46
+
--------------
47
+
minimum time:4.248 ns (0.00% GC)
48
+
median time:4.631 ns (0.00% GC)
49
+
mean time:5.502 ns (0.00% GC)
50
+
maximum time:60.995 ns (0.00% GC)
51
+
--------------
52
+
samples:10000
53
+
evals/sample:1000
54
+
```
55
+
56
+
For quick sanity checks, one can use the [`@btime` macro](https://github.com/JuliaCI/BenchmarkTools.jl/blob/master/doc/manual.md#benchmarking-basics), which is a convenience wrapper around `@benchmark` whose output is analogous to Julia's built-in [`@time` macro](https://docs.julialang.org/en/stable/stdlib/base/#Base.@time):
57
+
58
+
```julia
59
+
julia>@btimesin(x) setup=(x=rand())
60
+
4.361 ns (0 allocations:0 bytes)
61
+
0.49587200950472454
42
62
```
43
63
44
64
If the expression you want to benchmark depends on external variables, you should use [`$` to "interpolate"](https://github.com/JuliaCI/BenchmarkTools.jl/blob/master/doc/manual.md#interpolating-values-into-benchmark-expressions) them into the benchmark expression to
@@ -50,10 +70,10 @@ julia> A = rand(3,3);
50
70
51
71
julia>@btimeinv($A); # we interpolate the global variable A with $A
52
72
1.191 μs (10 allocations:2.31 KiB)
53
-
73
+
54
74
julia>@btimeinv($(rand(3,3))); # interpolation: the rand(3,3) call occurs before benchmarking
55
75
1.192 μs (10 allocations:2.31 KiB)
56
-
76
+
57
77
julia>@btimeinv(rand(3,3)); # the rand(3,3) call is included in the benchmark time
0 commit comments