Skip to content

Commit f0f22b6

Browse files
willow-ahrensjrevels
authored andcommitted
update BenchmarkTool's use of show to be API compliant for Julia 1.0 (#121)
1 parent af35d05 commit f0f22b6

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

doc/manual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ Following from the previous section, we see that running our benchmark suite ret
591591
julia> results["utf8"]
592592
BenchmarkTools.BenchmarkGroup:
593593
tags: ["string", "unicode"]
594-
"join" => Trial(133.84 ms) # showcompact for Trial displays the minimum time estimate
594+
"join" => Trial(133.84 ms) # summary(::Trial) displays the minimum time estimate
595595
"replace" => Trial(202.3 μs)
596596

597597
julia> results["trig"]

src/groups.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,24 @@ Base.setindex!(group::BenchmarkGroup, v, k::BenchmarkGroup) = error("A Benchmark
248248

249249
tagrepr(tags) = string("[", join(map(repr, tags), ", "), "]")
250250

251-
Base.show(io::IO, group::BenchmarkGroup) = print(io, "$(length(group))-element BenchmarkGroup($(tagrepr(group.tags)))")
251+
Base.summary(io::IO, group::BenchmarkGroup) = print(io, "$(length(group))-element BenchmarkGroup($(tagrepr(group.tags)))")
252252

253-
function Base.show(io::IO, mime::MIME"text/plain", group::BenchmarkGroup, pad = ""; verbose = false, limit = 10)
253+
function Base.show(io::IO, group::BenchmarkGroup)
254254
println(io, "$(length(group))-element BenchmarkTools.BenchmarkGroup:")
255+
pad = get(io, :pad, "")
255256
print(io, pad, " tags: ", tagrepr(group.tags))
256257
count = 1
257258
for (k, v) in group
258259
println(io)
259260
print(io, pad, " ", repr(k), " => ")
260-
if verbose && isa(v, BenchmarkGroup)
261-
show(io, mime, v, "\t"*pad; verbose = verbose, limit = limit)
261+
if get(io, :verbose, false) && isa(v, BenchmarkGroup)
262+
show(IOContext(io, :pad => "\t"*pad), v)
263+
elseif get(io, :compact, true)
264+
summary(IOContext(io, :pad => "\t"*pad), v)
262265
else
263-
show(io, v)
266+
show(IOContext(io, :pad => "\t"*pad), v)
264267
end
265-
count > limit && (println(io); print(io, pad, ""); break)
268+
count > get(io, :limit, 10) && (println(io); print(io, pad, ""); break)
266269
count += 1
267270
end
268271
end

src/trials.jl

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ function prettymemory(b)
262262
return string(@sprintf("%.2f", value), " ", units)
263263
end
264264

265-
Base.show(io::IO, t::Trial) = print(io, "Trial(", prettytime(time(t)), ")")
266-
Base.show(io::IO, t::TrialEstimate) = print(io, "TrialEstimate(", prettytime(time(t)), ")")
267-
Base.show(io::IO, t::TrialRatio) = print(io, "TrialRatio(", prettypercent(time(t)), ")")
268-
Base.show(io::IO, t::TrialJudgement) = print(io, "TrialJudgement(", prettydiff(time(ratio(t))), " => ", time(t), ")")
265+
Base.summary(io::IO, t::Trial) = print(io, "Trial(", prettytime(time(t)), ")")
266+
Base.summary(io::IO, t::TrialEstimate) = print(io, "TrialEstimate(", prettytime(time(t)), ")")
267+
Base.summary(io::IO, t::TrialRatio) = print(io, "TrialRatio(", prettypercent(time(t)), ")")
268+
Base.summary(io::IO, t::TrialJudgement) = print(io, "TrialJudgement(", prettydiff(time(ratio(t))), " => ", time(t), ")")
269269

270-
function Base.show(io::IO, ::MIME"text/plain", t::Trial)
270+
function Base.show(io::IO, t::Trial)
271271
if length(t) > 0
272272
min = minimum(t)
273273
max = maximum(t)
@@ -288,36 +288,40 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
288288
meanstr = "N/A"
289289
end
290290
println(io, "BenchmarkTools.Trial: ")
291-
println(io, " memory estimate: ", memorystr)
292-
println(io, " allocs estimate: ", allocsstr)
293-
println(io, " --------------")
294-
println(io, " minimum time: ", minstr)
295-
println(io, " median time: ", medstr)
296-
println(io, " mean time: ", meanstr)
297-
println(io, " maximum time: ", maxstr)
298-
println(io, " --------------")
299-
println(io, " samples: ", length(t))
300-
print(io, " evals/sample: ", t.params.evals)
291+
pad = get(io, :pad, "")
292+
println(io, pad, " memory estimate: ", memorystr)
293+
println(io, pad, " allocs estimate: ", allocsstr)
294+
println(io, pad, " --------------")
295+
println(io, pad, " minimum time: ", minstr)
296+
println(io, pad, " median time: ", medstr)
297+
println(io, pad, " mean time: ", meanstr)
298+
println(io, pad, " maximum time: ", maxstr)
299+
println(io, pad, " --------------")
300+
println(io, pad, " samples: ", length(t))
301+
print(io, pad, " evals/sample: ", t.params.evals)
301302
end
302303

303-
function Base.show(io::IO, ::MIME"text/plain", t::TrialEstimate)
304+
function Base.show(io::IO, t::TrialEstimate)
304305
println(io, "BenchmarkTools.TrialEstimate: ")
305-
println(io, " time: ", prettytime(time(t)))
306-
println(io, " gctime: ", prettytime(gctime(t)), " (", prettypercent(gctime(t) / time(t)),")")
307-
println(io, " memory: ", prettymemory(memory(t)))
308-
print(io, " allocs: ", allocs(t))
306+
pad = get(io, :pad, "")
307+
println(io, pad, " time: ", prettytime(time(t)))
308+
println(io, pad, " gctime: ", prettytime(gctime(t)), " (", prettypercent(gctime(t) / time(t)),")")
309+
println(io, pad, " memory: ", prettymemory(memory(t)))
310+
print(io, pad, " allocs: ", allocs(t))
309311
end
310312

311-
function Base.show(io::IO, ::MIME"text/plain", t::TrialRatio)
313+
function Base.show(io::IO, t::TrialRatio)
312314
println(io, "BenchmarkTools.TrialRatio: ")
313-
println(io, " time: ", time(t))
314-
println(io, " gctime: ", gctime(t))
315-
println(io, " memory: ", memory(t))
316-
print(io, " allocs: ", allocs(t))
315+
pad = get(io, :pad, "")
316+
println(io, pad, " time: ", time(t))
317+
println(io, pad, " gctime: ", gctime(t))
318+
println(io, pad, " memory: ", memory(t))
319+
print(io, pad, " allocs: ", allocs(t))
317320
end
318321

319-
function Base.show(io::IO, ::MIME"text/plain", t::TrialJudgement)
322+
function Base.show(io::IO, t::TrialJudgement)
320323
println(io, "BenchmarkTools.TrialJudgement: ")
321-
println(io, " time: ", prettydiff(time(ratio(t))), " => ", time(t), " (", prettypercent(params(t).time_tolerance), " tolerance)")
322-
print(io, " memory: ", prettydiff(memory(ratio(t))), " => ", memory(t), " (", prettypercent(params(t).memory_tolerance), " tolerance)")
324+
pad = get(io, :pad, "")
325+
println(io, pad, " time: ", prettydiff(time(ratio(t))), " => ", time(t), " (", prettypercent(params(t).time_tolerance), " tolerance)")
326+
print(io, pad, " memory: ", prettydiff(memory(ratio(t))), " => ", memory(t), " (", prettypercent(params(t).memory_tolerance), " tolerance)")
323327
end

0 commit comments

Comments
 (0)