Skip to content

Commit 969c071

Browse files
authored
Merge pull request #312 from gdalle/patch-1
Clarify multiple setup values
2 parents d926110 + 05d103e commit 969c071

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/src/manual.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ In the above example, we wish to benchmark Julia's in-place sorting method. With
237237

238238
Note that the `setup` and `teardown` phases are **executed for each sample, not each evaluation**. Thus, the sorting example above wouldn't produce the intended results if `evals/sample > 1` (it'd suffer from the same problem of benchmarking against an already sorted vector).
239239

240+
If your setup involves several objects, you need to wrap them in a tuple as follows:
241+
242+
```julia
243+
julia> @btime x + y setup = ((x, y) = (1, 2)) # works
244+
1.238 ns (0 allocations: 0 bytes)
245+
3
246+
247+
julia> @btime x + y setup = (x=1, y=2) # errors
248+
ERROR: UndefVarError: `x` not defined
249+
```
250+
251+
This also explains the error you get if you accidentally put a comma in the setup for a single argument:
252+
253+
```julia
254+
julia> @btime exp(x) setup = (x=1,) # errors
255+
ERROR: UndefVarError: `x` not defined
256+
```
257+
240258
### Understanding compiler optimizations
241259

242260
It's possible for LLVM and Julia's compiler to perform optimizations on `@benchmarkable` expressions. In some cases, these optimizations can elide a computation altogether, resulting in unexpectedly "fast" benchmarks. For example, the following expression is non-allocating:

0 commit comments

Comments
 (0)