@@ -13,12 +13,13 @@ function benchmark(init, setup, fs::Tuple{Vararg{Any, N}}, teardown;
1313 evals:: Union{Int, Nothing} = nothing ,
1414 samples:: Union{Int, Nothing} = nothing ,
1515 seconds:: Union{Real, Nothing} = (samples=== nothing ? DEFAULTS. seconds : 10 * DEFAULTS. seconds)* N,
16- gc:: Bool = DEFAULTS. gc) where N
17- _benchmark_1 (init, setup, teardown, evals, samples, seconds, gc, fs... )
16+ gc:: Bool = DEFAULTS. gc,
17+ warmup:: Union{Bool, Nothing} = nothing ) where N
18+ _benchmark_1 (init, setup, teardown, evals, samples, seconds, gc, warmup, fs... )
1819end
19- _benchmark_1 (init, setup, teardown, evals:: Union{Int, Nothing} , samples:: Union{Int, Nothing} , seconds:: Real , gc:: Bool , fs... ) =
20- _benchmark_1 (init, setup, teardown, evals, samples, Float64 (seconds), gc, fs... )
21- function _benchmark_1 (init, setup, teardown, evals:: Union{Int, Nothing} , samples:: Union{Int, Nothing} , seconds:: Union{Float64, Nothing} , gc:: Bool , fs... )
20+ _benchmark_1 (init, setup, teardown, evals:: Union{Int, Nothing} , samples:: Union{Int, Nothing} , seconds:: Real , gc:: Bool , warmup :: Union{Bool, Nothing} , fs... ) =
21+ _benchmark_1 (init, setup, teardown, evals, samples, Float64 (seconds), gc, warmup, fs... )
22+ function _benchmark_1 (init, setup, teardown, evals:: Union{Int, Nothing} , samples:: Union{Int, Nothing} , seconds:: Union{Float64, Nothing} , gc:: Bool , warmup :: Union{Bool, Nothing} , fs... )
2223 @nospecialize
2324 N = length (fs)
2425
@@ -37,16 +38,24 @@ function _benchmark_1(init, setup, teardown, evals::Union{Int, Nothing}, samples
3738
3839 samples == 0 && return ntuple (i -> Benchmark ([_benchmark_2 (args1, setup, teardown, gc, evals, false , fs... )[1 ][i]]), N)
3940
40- warmup, start_time = _benchmark_2 (args1, setup, teardown, gc, 1 , false , fs... )
41+ warmup_result, start_time = if warmup === false
42+ if seconds == 0
43+ _benchmark_2 (args1, setup, teardown, gc, 1 , true , fs... )
44+ else
45+ (nothing , time_ns ())
46+ end
47+ else
48+ _benchmark_2 (args1, setup, teardown, gc, 1 , false , fs... )
49+ end
4150
42- seconds == 0 && return ntuple (i -> Benchmark ([warmup [i]]), N)
51+ seconds == 0 && return ntuple (i -> Benchmark ([warmup_result [i]]), N)
4352 new_evals = if evals === nothing
4453 @assert evals === samples === nothing && seconds != = nothing
4554
46- if sum (w. time for w in warmup ) > 2 seconds && all (w. compile_fraction < .5 for w in warmup )
55+ if warmup === nothing && sum (w. time for w in warmup_result ) > 2 seconds && all (w. compile_fraction < .5 for w in warmup_result )
4756 # The estimated runtime in the warmup already exceeds the time budget.
4857 # Return the warmup result (which is marked as not having a warmup).
49- return ntuple (i -> Benchmark ([warmup [i]]), N)
58+ return ntuple (i -> Benchmark ([warmup_result [i]]), N)
5059 end
5160
5261 calibration1, time = _benchmark_2 (args1, setup, teardown, gc, 1 , true , fs... )
0 commit comments