Skip to content

Benchmarked function is run one more time than specified #382

@flenzen

Description

@flenzen

Consider the following example:

first_run = false
function f()
  global first_run
  if !first_run; first_run = true; else sleep(1); end
  println(time())
end
@benchmark f() evals=1 samples=1 

which outputs
1.734518515199018e9
1.734518516201369e9
BenchmarkTools.Trial: 1 sample with 1 evaluation.
Single result which took 1.002 s (0.00% GC) to evaluate,
with a memory estimate of 624 bytes, over 11 allocations.

It seems that `f` is run an additional time before the actual sample is taken. This seems not to be documented. I wonder if this is to even compilation time out. If yes, where do I find information about that? In particular, is it possible to skip this, or trigger compilation with a cheaper instance?

Run on Julia 1.10 with BenchmarkTools v1.5.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions