driver.rb: plain text table
* benchmark/driver.rb (show_results): support plain text style table format output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d816b8e4e6
commit
e5eb9a16df
@ -121,10 +121,23 @@ class BenchmarkDriver
|
|||||||
def show_results
|
def show_results
|
||||||
case @opt[:format]
|
case @opt[:format]
|
||||||
when :tsv
|
when :tsv
|
||||||
|
strformat = "\t%1$s"
|
||||||
|
numformat = "\t%1$*2$.3f"
|
||||||
|
minwidth = 0
|
||||||
|
name_width = 0
|
||||||
when :markdown
|
when :markdown
|
||||||
markdown = true
|
markdown = true
|
||||||
|
strformat = "|%1$-*2$s"
|
||||||
|
numformat = "|%1$*2$.3f"
|
||||||
|
when :plain
|
||||||
|
strformat = " %1$-*2$s"
|
||||||
|
numformat = " %1$*2$.3f"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
name_width ||= @name_width
|
||||||
|
minwidth ||= 7
|
||||||
|
width = @execs.map{|(_, v)| [v.size, minwidth].max}
|
||||||
|
|
||||||
output
|
output
|
||||||
|
|
||||||
if @verbose
|
if @verbose
|
||||||
@ -151,28 +164,26 @@ class BenchmarkDriver
|
|||||||
output "minimum results in each #{@repeat} measurements."
|
output "minimum results in each #{@repeat} measurements."
|
||||||
end
|
end
|
||||||
|
|
||||||
tabs = @name_width / 8
|
|
||||||
sep = markdown ? "\t|" : "\t"
|
|
||||||
output "Execution time (sec)"
|
output "Execution time (sec)"
|
||||||
output if markdown
|
output if markdown
|
||||||
output ["name", @execs.map{|(_, v)| v}].join(sep)
|
output ["name".ljust(name_width), @execs.map.with_index{|(_, v), i| sprintf(strformat, v, width[i])}].join("").rstrip
|
||||||
output "-"*(8*tabs+8)+"|------:"*@execs.size if markdown
|
output ["-"*name_width, width.map{|n|":".rjust(n, "-")}].join("|") if markdown
|
||||||
@results.each{|v, result|
|
@results.each_with_index{|(v, result), i|
|
||||||
rets = []
|
rets = []
|
||||||
s = adjusted_results(v, result){|r|
|
s = adjusted_results(v, result){|r|
|
||||||
rets << sprintf("%.3f", r)
|
rets << sprintf(numformat, r, width[i])
|
||||||
}
|
}
|
||||||
v += s if s
|
v += s if s
|
||||||
output [v, rets].join(sep)
|
output [v.ljust(name_width), rets].join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
if @execs.size > 1
|
if @execs.size > 1
|
||||||
output
|
output
|
||||||
output "Speedup ratio: compare with the result of `#{@execs[0][1]}' (greater is better)"
|
output "Speedup ratio: compare with the result of `#{@execs[0][1]}' (greater is better)"
|
||||||
output if markdown
|
output if markdown
|
||||||
output ["name", @execs[1..-1].map{|(_, v)| v}].join(sep)
|
output ["name".ljust(name_width), @execs[1..-1].map.with_index{|(_, v), i| sprintf(strformat, v, width[i])}].join("").rstrip
|
||||||
output "-"*(8*tabs+8)+"|------:"*(@execs.size-1) if markdown
|
output ["-"*name_width, width[1..-1].map{|n|":".rjust(n, "-")}].join("|") if markdown
|
||||||
@results.each{|v, result|
|
@results.each_with_index{|(v, result), i|
|
||||||
rets = []
|
rets = []
|
||||||
first_value = nil
|
first_value = nil
|
||||||
s = adjusted_results(v, result){|r|
|
s = adjusted_results(v, result){|r|
|
||||||
@ -180,14 +191,14 @@ class BenchmarkDriver
|
|||||||
if r == 0
|
if r == 0
|
||||||
rets << "Error"
|
rets << "Error"
|
||||||
else
|
else
|
||||||
rets << sprintf("%.3f", first_value/r)
|
rets << sprintf(numformat, first_value/r, width[i])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
first_value = r
|
first_value = r
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
v += s if s
|
v += s if s
|
||||||
output [v, rets].join(sep)
|
output [v.ljust(name_width), rets].join("")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -297,6 +308,7 @@ if __FILE__ == $0
|
|||||||
formats = {
|
formats = {
|
||||||
:tsv => ".tsv",
|
:tsv => ".tsv",
|
||||||
:markdown => ".md",
|
:markdown => ".md",
|
||||||
|
:plain => ".txt",
|
||||||
}
|
}
|
||||||
|
|
||||||
parser = OptionParser.new{|o|
|
parser = OptionParser.new{|o|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user