@@ -106,12 +106,15 @@ end
106
106
# Note that trials executed via `run` and `lineartrial` are always executed at top-level
107
107
# scope, in order to allow transfer of locally-scoped variables into benchmark scope.
108
108
109
- function _run (b:: Benchmark , p:: Parameters ; verbose= false , pad= " " , kwargs... )
109
+ function _run (b:: Benchmark , p:: Parameters ; verbose= false , pad= " " , warmup = true , kwargs... )
110
110
params = Parameters (p; kwargs... )
111
111
@assert params. seconds > 0.0 " time limit must be greater than 0.0"
112
112
params. gctrial && gcscrub ()
113
113
start_time = Base. time ()
114
114
trial = Trial (params)
115
+ if warmup
116
+ b. samplefunc (b. quote_vals, Parameters (params; evals= 1 )) # warmup sample
117
+ end
115
118
params. gcsample && gcscrub ()
116
119
s = b. samplefunc (b. quote_vals, params)
117
120
push! (trial, s[1 : (end - 1 )]. .. )
@@ -180,6 +183,8 @@ function _lineartrial(b::Benchmark, p::Parameters=b.params; maxevals=RESOLUTION,
180
183
params = Parameters (p; kwargs... )
181
184
estimates = zeros (maxevals)
182
185
completed = 0
186
+ params. evals = 1
187
+ b. samplefunc (b. quote_vals, params) # warmup sample
183
188
params. gctrial && gcscrub ()
184
189
start_time = time ()
185
190
for evals in eachindex (estimates)
@@ -193,6 +198,10 @@ function _lineartrial(b::Benchmark, p::Parameters=b.params; maxevals=RESOLUTION,
193
198
end
194
199
195
200
function warmup (item; verbose:: Bool = true )
201
+ Base. depwarn (
202
+ " `warmup` is deprecated because `run` now warms up every time automatically" ,
203
+ :warmup ,
204
+ )
196
205
return run (item; verbose= verbose, samples= 1 , evals= 1 , gctrial= false , gcsample= false )
197
206
end
198
207
@@ -288,7 +297,6 @@ function tune!(
288
297
kwargs... ,
289
298
)
290
299
if ! p. evals_set
291
- warmup (b; verbose= false )
292
300
estimate = ceil (Int, minimum (lineartrial (b, p; kwargs... )))
293
301
b. params. evals = guessevals (estimate)
294
302
end
@@ -436,9 +444,8 @@ macro benchmark(args...)
436
444
return esc (
437
445
quote
438
446
local $ tmp = $ BenchmarkTools. @benchmarkable $ (args... )
439
- $ BenchmarkTools. warmup ($ tmp)
440
447
$ (hasevals (params) ? :() : :($ BenchmarkTools. tune! ($ tmp)))
441
- $ BenchmarkTools. run ($ tmp)
448
+ $ BenchmarkTools. run ($ tmp; warmup = $ ( hasevals (params)) )
442
449
end ,
443
450
)
444
451
end
@@ -656,9 +663,10 @@ macro btime(args...)
656
663
return esc (
657
664
quote
658
665
local $ bench = $ BenchmarkTools. @benchmarkable $ (args... )
659
- $ BenchmarkTools. warmup ($ bench)
660
666
$ tune_phase
661
- local $ trial, $ result = $ BenchmarkTools. run_result ($ bench)
667
+ local $ trial, $ result = $ BenchmarkTools. run_result (
668
+ $ bench; warmup= $ (hasevals (params))
669
+ )
662
670
local $ trialmin = $ BenchmarkTools. minimum ($ trial)
663
671
local $ trialallocs = $ BenchmarkTools. allocs ($ trialmin)
664
672
println (
@@ -704,10 +712,18 @@ macro bprofile(args...)
704
712
return esc (
705
713
quote
706
714
local $ tmp = $ BenchmarkTools. @benchmarkable $ (args... )
707
- $ BenchmarkTools. warmup ($ tmp)
708
- $ (hasevals (params) ? :() : :($ BenchmarkTools. tune! ($ tmp)))
715
+ $ (
716
+ if hasevals (params)
717
+ :(run (
718
+ $ tmp, $ BenchmarkTools. Parameters ($ tmp. params; evals= 1 ); warmup= false
719
+ ))
720
+ else
721
+ :($ BenchmarkTools. tune! ($ tmp))
722
+ end
723
+ )
709
724
$ BenchmarkTools. Profile. clear ()
710
- $ BenchmarkTools. @profile $ BenchmarkTools. run ($ tmp)
725
+ # TODO : improve @bprofile to only measure the running code and none of the setup
726
+ $ BenchmarkTools. @profile $ BenchmarkTools. run ($ tmp, $ tmp. params; warmup= false )
711
727
end ,
712
728
)
713
729
end
0 commit comments