Skip to content

Commit

Permalink
Merge pull request #373 from KlausC/krc/no_empty_varargs
Browse files Browse the repository at this point in the history
no empty varargs
  • Loading branch information
willow-ahrens authored Dec 30, 2024
2 parents 506fe58 + db65100 commit 5b76b55
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ Base.iterate(group::BenchmarkGroup, i=1) = iterate(group.data, i)
andexpr(a, b) = :($a && $b)
andreduce(preds) = reduce(andexpr, preds)

function mapvals!(f, dest::BenchmarkGroup, srcs::BenchmarkGroup...)
for k in keys(first(srcs))
function mapvals!(f, dest::BenchmarkGroup, src::BenchmarkGroup, srcs::BenchmarkGroup...)
for k in keys(src)
if all(s -> haskey(s, k), srcs)
dest[k] = f((s[k] for s in srcs)...)
dest[k] = f(src[k], (s[k] for s in srcs)...)
end
end
return dest
end

mapvals!(f, group::BenchmarkGroup) = mapvals!(f, similar(group), group)
mapvals(f, groups::BenchmarkGroup...) = mapvals!(f, similar(first(groups)), groups...)
function mapvals(f, group::BenchmarkGroup, groups::BenchmarkGroup...)
return mapvals!(f, similar(group), group, groups...)
end

filtervals!(f, group::BenchmarkGroup) = (filter!(kv -> f(kv[2]), group.data); return group)
filtervals(f, group::BenchmarkGroup) = filtervals!(f, copy(group))
Expand All @@ -109,22 +111,22 @@ Statistics.mean(group::BenchmarkGroup) = mapvals(mean, group)
Statistics.median(group::BenchmarkGroup) = mapvals(median, group)
Statistics.std(group::BenchmarkGroup) = mapvals(std, group)
Statistics.var(group::BenchmarkGroup) = mapvals(var, group)
Base.min(groups::BenchmarkGroup...) = mapvals(min, groups...)
Base.max(groups::BenchmarkGroup...) = mapvals(max, groups...)
Base.min(group::BenchmarkGroup, groups::BenchmarkGroup...) = mapvals(min, group, groups...)
Base.max(group::BenchmarkGroup, groups::BenchmarkGroup...) = mapvals(max, group, groups...)

Base.time(group::BenchmarkGroup) = mapvals(time, group)
gctime(group::BenchmarkGroup) = mapvals(gctime, group)
memory(group::BenchmarkGroup) = mapvals(memory, group)
allocs(group::BenchmarkGroup) = mapvals(allocs, group)
params(group::BenchmarkGroup) = mapvals(params, group)

ratio(groups::BenchmarkGroup...) = mapvals(ratio, groups...)
ratio(group::BenchmarkGroup, groups::BenchmarkGroup...) = mapvals(ratio, group, groups...)

"""
judge(target::BenchmarkGroup, baseline::BenchmarkGroup; [time_tolerance::Float64=0.05])
"""
function judge(groups::BenchmarkGroup...; kwargs...)
return mapvals((x...) -> judge(x...; kwargs...), groups...)
function judge(group::BenchmarkGroup, groups::BenchmarkGroup...; kwargs...)
return mapvals((x...) -> judge(x...; kwargs...), group, groups...)
end

rmskew!(group::BenchmarkGroup) = mapvals!(rmskew!, group)
Expand Down
9 changes: 9 additions & 0 deletions test/ExecutionTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,13 @@ b = x = nothing
GC.gc()
@test x_finalized

# Ensure mapvals(f) throws MethodError
@test_throws MethodError BenchmarkTools.mapvals(max)

# Ensure those function are not defined without arguments
@test_throws MethodError max()
@test_throws MethodError min()
@test_throws MethodError ratio()
@test_throws MethodError judge()

end # module

0 comments on commit 5b76b55

Please sign in to comment.