Skip to content

Commit

Permalink
Allow calibration to request a number of evals up to and exceeding ty…
Browse files Browse the repository at this point in the history
…pemax(Int); round down to typemax(Int) instead of erroring
  • Loading branch information
LilithHafner committed Nov 24, 2024
1 parent 3bca76f commit d87265e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/benchmarking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ maybecall(::Nothing, x::Tuple{}) = x
maybecall(f, x::Tuple{Any}) = (f(only(x)),)
maybecall(f::Function, ::Tuple{}) = (f(),)
maybecall(x, ::Tuple{}) = (x,)
floor_to_Int(x::Float64) = x >= Float64(typemax(Int)) ? typemax(Int) : floor(Int, x)
function benchmark(init, setup, fs::Tuple{Vararg{Any, N}}, teardown;
evals::Union{Int, Nothing}=nothing,
samples::Union{Int, Nothing}=nothing,
Expand Down Expand Up @@ -67,12 +68,12 @@ function _benchmark_1(init, setup, teardown, evals::Union{Int, Nothing}, samples
if calibration1time < .00015seconds # This branch protects us against cases where runtime is dominated by the reduction.
calibration2, time = _benchmark_2(args1, setup, teardown, gc, 10, true, fs...)
calibration2time = sum(s.time for s in calibration2)
trials = floor(Int, .05seconds/(calibration2time+1e-9))
trials = floor_to_Int(.05seconds/(calibration2time+1e-9))
if trials > 20
calibration2, time = _benchmark_2(args1, setup, teardown, gc, trials, true, fs...)
end
elseif calibration1time < .01seconds
calibration2, time = _benchmark_2(args1, setup, teardown, gc, floor(Int, .05seconds/(calibration1time+1e-9)), true, fs...)
calibration2, time = _benchmark_2(args1, setup, teardown, gc, floor_to_Int(.05seconds/(calibration1time+1e-9)), true, fs...)
end
if calibration2 !== nothing
calibration2time = sum(s.time for s in calibration2)
Expand All @@ -90,7 +91,7 @@ function _benchmark_1(init, setup, teardown, evals::Union{Int, Nothing}, samples
# exp(evalpoly(log(seconds), (-log(30e-9)^2/4log(1000),1+(2log(30e-9)/4log(1000)),-1/4log(1000))))
end

max(1, floor(Int, target_sample_time/(something(calibration2time, calibration1time)+1e-9)))
max(1, floor_to_Int(target_sample_time/(something(calibration2time, calibration1time)+1e-9)))
else
evals
end
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ if ("RegressionTests" => "true") ∉ ENV
@test Chairmarks.writefixed(-0.005, 4) == "-0.0050"
end

@testset "floor_to_Int" begin
@test Chairmarks.floor_to_Int(17.29) === 17
@test Chairmarks.floor_to_Int(typemax(Int) + 0.5) === typemax(Int)
@test Chairmarks.floor_to_Int(typemax(Int) + 1.5) === typemax(Int)
@test Chairmarks.floor_to_Int(typemax(Int) + 17.29) === typemax(Int)
@test Chairmarks.floor_to_Int(Inf) === typemax(Int)
@test Chairmarks.floor_to_Int(Float64(typemax(Int))) === typemax(Int)
@test Chairmarks.floor_to_Int(prevfloat(Float64(typemax(Int)))) < typemax(Int)
@test Chairmarks.floor_to_Int(nextfloat(Float64(typemax(Int)))) === typemax(Int)
end

@testset "DEFAULTS" begin
@test Chairmarks.DEFAULTS.seconds === 0.1
@test Chairmarks.DEFAULTS.gc === true
Expand Down

0 comments on commit d87265e

Please sign in to comment.