[前][次][番号順一覧][スレッド一覧]

ruby-changes:37765

From: nobu <ko1@a...>
Date: Thu, 5 Mar 2015 09:14:10 +0900 (JST)
Subject: [ruby-changes:37765] nobu:r49846 (trunk): driver.rb: MarkDown table

nobu	2015-03-05 09:14:02 +0900 (Thu, 05 Mar 2015)

  New Revision: 49846

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49846

  Log:
    driver.rb: MarkDown table
    
    * benchmark/driver.rb (show_results): support MarkDown style table
      format output.

  Modified files:
    trunk/benchmark/driver.rb
Index: benchmark/driver.rb
===================================================================
--- benchmark/driver.rb	(revision 49845)
+++ benchmark/driver.rb	(revision 49846)
@@ -81,6 +81,7 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L81
     @loop_wl1 = @loop_wl2 = nil
     @ruby_arg = opt[:ruby_arg] || nil
     @opt = opt
+    @name_width = 4             # "name".size
 
     # [[name, [[r-1-1, r-1-2, ...], [r-2-1, r-2-2, ...]]], ...]
     @results = []
@@ -118,6 +119,12 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L119
   end
 
   def show_results
+    case @opt[:format]
+    when :tsv
+    when :markdown
+      markdown = true
+    end
+
     output
 
     if @verbose
@@ -144,20 +151,27 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L151
       output "minimum results in each #{@repeat} measurements."
     end
 
+    tabs = @name_width / 8
+    sep = markdown ? "\t|" : "\t"
     output "Execution time (sec)"
-    output "name\t#{@execs.map{|(_, v)| v}.join("\t")}"
+    output if markdown
+    output ["name", @execs.map{|(_, v)| v}].join(sep)
+    output "-"*(8*tabs+8)+"|------:"*@execs.size if markdown
     @results.each{|v, result|
       rets = []
       s = adjusted_results(v, result){|r|
         rets << sprintf("%.3f", r)
       }
-      output "#{v}#{s}\t#{rets.join("\t")}"
+      v += s if s
+      output [v, rets].join(sep)
     }
 
     if @execs.size > 1
       output
       output "Speedup ratio: compare with the result of `#{@execs[0][1]}' (greater is better)"
-      output "name\t#{@execs[1..-1].map{|(_, v)| v}.join("\t")}"
+      output if markdown
+      output ["name", @execs[1..-1].map{|(_, v)| v}].join(sep)
+      output "-"*(8*tabs+8)+"|------:"*(@execs.size-1) if markdown
       @results.each{|v, result|
         rets = []
         first_value = nil
@@ -172,7 +186,8 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L186
             first_value = r
           end
         }
-        output "#{v}#{s}\t#{rets.join("\t")}"
+        v += s if s
+        output [v, rets].join(sep)
       }
     end
 
@@ -232,6 +247,7 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L247
       output
     end
 
+    @name_width = name.size if name.size > @name_width
     result = [name]
     result << @execs.map{|(e, v)|
       (0...@repeat).map{
@@ -275,7 +291,8 @@ if __FILE__ == $0 https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L291
     :dir => File.dirname(__FILE__),
     :repeat => 1,
     :output => "bmlog-#{Time.now.strftime('%Y%m%d-%H%M%S')}.#{$$}",
-    :raw_output => nil
+    :raw_output => nil,
+    :format => :tsv,
   }
 
   parser = OptionParser.new{|o|
@@ -306,6 +323,9 @@ if __FILE__ == $0 https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L323
     o.on('--rawdata-output [FILE]', 'output rawdata'){|r|
       opt[:rawdata_output] = r
     }
+    o.on('-f', '--format={tsv,markdown}', 'output format', [:tsv, :markdown]){|r|
+      opt[:format] = r
+    }
     o.on('-v', '--verbose'){|v|
       opt[:verbose] = v
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]