Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no empty varargs #373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,18 +111,18 @@ 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...)
function judge(groups::BenchmarkGroup...; kwargs...)
return mapvals((x...) -> judge(x...; kwargs...), groups...)
ratio(group::BenchmarkGroup, groups::BenchmarkGroup...) = mapvals(ratio, group, 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 @@ -382,4 +382,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
Loading