Skip to content

Commit

Permalink
fix show methods in light of JuliaLang/julia#16354 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels committed May 30, 2016
1 parent 095b435 commit fb33ddf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
12 changes: 3 additions & 9 deletions src/BenchmarkTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ module BenchmarkTools

using Compat

# Used to patch showcompact compatibility between v0.4 and v0.5.
# We can't just define something like
#
# Base.showcompact(io, x) = show(IOContext(io, limit_output = true), x)
#
# because showcompact then gets used by default by the REPL display methods,
# which is pretty annoying.
if VERSION < v"0.5-"
limit_output(io) = false
# `show` compatibility for pre-JuliaLang/julia#16354 builds
if VERSION < v"0.5.0-dev+4305"
Base.get(io::IO, setting::Symbol, default::Bool) = default
end

##############
Expand Down
14 changes: 7 additions & 7 deletions src/groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Base.showall(io::IO, group::BenchmarkGroup) = show(io, group; verbose = true, li
# written this way for v0.5/v0.4 compatibility
_showcompact(io::IO, group::BenchmarkGroup) = print(io, "$(length(group))-element BenchmarkGroup($(tagrepr(group.tags)))")

if VERSION < v"0.5-"
if VERSION < v"0.5.0-dev+4305"
Base.showcompact(io::IO, group::BenchmarkGroup) = _showcompact(io, group)
function Base.show(io::IO, group::BenchmarkGroup, pad = ""; verbose = false, limit = 10)
println(io, "$(length(group))-element BenchmarkTools.BenchmarkGroup:")
Expand All @@ -258,24 +258,24 @@ if VERSION < v"0.5-"
end
else
function Base.show(io::IO, group::BenchmarkGroup, pad = ""; verbose = false, limit = 10)
if limit_output(io)
_showcompact(io, group)
else
if get(io, :multiline, true)
println(io, "$(length(group))-element BenchmarkTools.BenchmarkGroup:")
print(io, pad, " tags: ", tagrepr(group.tags))
count = 1
element_io = verbose ? io : IOContext(io, :limit_output => true)
element_io = verbose ? io : IOContext(io, :multiline => false)
for (k, v) in group
println(io)
print(io, pad, " ", repr(k), " => ")
if verbose && isa(v, BenchmarkGroup)
show(io, v, "\t"*pad; verbose = verbose, limit = limit)
show(element_io, v, "\t"*pad; verbose = verbose, limit = limit)
else
show(io, v)
show(element_io, v)
end
count > limit && (println(io); print(io, pad, ""); break)
count += 1
end
else
_showcompact(io, t)
end
end
end
24 changes: 12 additions & 12 deletions src/trials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ if VERSION < v"0.5-"
end

function Base.show(io::IO, t::Trial)
if limit_output(io)
_showcompact(io, t)
else
if get(io, :multiline, true)
if length(t) > 0
min = minimum(t)
max = maximum(t)
Expand Down Expand Up @@ -309,43 +307,45 @@ function Base.show(io::IO, t::Trial)
println(io, " median time: ", maxstr)
println(io, " mean time: ", medstr)
print(io, " maximum time: ", meanstr)
else
_showcompact(io, t)
end
end

function Base.show(io::IO, t::TrialEstimate)
if limit_output(io)
_showcompact(io, t)
else
if get(io, :multiline, true)
println(io, "BenchmarkTools.TrialEstimate: ")
println(io, " time: ", prettytime(time(t)))
println(io, " gctime: ", prettytime(gctime(t)), " (", prettypercent(gctime(t) / time(t)),")")
println(io, " memory: ", prettymemory(memory(t)))
println(io, " allocs: ", allocs(t))
println(io, " time tolerance: ", prettypercent(params(t).time_tolerance))
print(io, " memory tolerance: ", prettypercent(params(t).memory_tolerance))
else
_showcompact(io, t)
end
end

function Base.show(io::IO, t::TrialRatio)
if limit_output(io)
_showcompact(io, t)
else
if get(io, :multiline, true)
println(io, "BenchmarkTools.TrialRatio: ")
println(io, " time: ", time(t))
println(io, " gctime: ", gctime(t))
println(io, " memory: ", memory(t))
println(io, " allocs: ", allocs(t))
println(io, " time tolerance: ", prettypercent(params(t).time_tolerance))
print(io, " memory tolerance: ", prettypercent(params(t).memory_tolerance))
else
_showcompact(io, t)
end
end

function Base.show(io::IO, t::TrialJudgement)
if limit_output(io)
_showcompact(io, t)
else
if get(io, :multiline, true)
println(io, "BenchmarkTools.TrialJudgement: ")
println(io, " time: ", prettydiff(time(ratio(t))), " => ", time(t), " (", prettypercent(params(t).time_tolerance), " tolerance)")
print(io, " memory: ", prettydiff(memory(ratio(t))), " => ", memory(t), " (", prettypercent(params(t).memory_tolerance), " tolerance)")
else
_showcompact(io, t)
end
end

0 comments on commit fb33ddf

Please sign in to comment.