Skip to content

Commit

Permalink
Fix off by one error in sample count (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner authored Apr 6, 2024
1 parent 5aa41f9 commit 6d0d58b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/benchmarking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function benchmark(init, setup, f, teardown; evals::Union{Int, Nothing}=nothing,
samples === nothing ? push!(data, sample) : (data[i += 1] = sample)
end

samples === nothing || resize!(data, i-1)
samples === nothing || resize!(data, i)

Benchmark(data)
end
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ using Chairmarks: Sample, Benchmark
@test length(res.samples) < 100
end

@testset "low sample count (#91)" begin
b = @be sleep(.001) evals=4 samples=0
@test Chairmarks.only(b.samples).warmup == 0 # Qualify only for compat
@test_broken Chairmarks.only(b.samples).evals == 4

b = @be sleep(.001) evals=4 samples=1
@test Chairmarks.only(b.samples).warmup == 1
@test Chairmarks.only(b.samples).evals == 4

b = @be sleep(.001) evals=4 samples=2
@test length(b.samples) == 2
@test all(s -> s.warmup == 1 && s.evals == 4, b.samples)
end

@testset "errors" begin
@test_throws UndefKeywordError Sample(allocs=1.5, bytes=1729) # needs `time`
end
Expand Down

0 comments on commit 6d0d58b

Please sign in to comment.