ruby-changes:37787
From: nobu <ko1@a...>
Date: Fri, 6 Mar 2015 10:33:44 +0900 (JST)
Subject: [ruby-changes:37787] nobu:r49868 (trunk): driver.rb: rawdata format
nobu 2015-03-06 10:33:39 +0900 (Fri, 06 Mar 2015) New Revision: 49868 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49868 Log: driver.rb: rawdata format * benchmark/driver.rb (show_results): dump the rawdata in some formats, yaml, json, and pretty_inspect. Modified files: trunk/benchmark/driver.rb Index: benchmark/driver.rb =================================================================== --- benchmark/driver.rb (revision 49867) +++ benchmark/driver.rb (revision 49868) @@ -77,7 +77,6 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L77 @exclude = opt[:exclude] || nil @verbose = opt[:quiet] ? false : (opt[:verbose] || false) @output = opt[:output] ? open(opt[:output], 'w') : nil - @rawdata_output = opt[:rawdata_output] ? open(opt[:rawdata_output], 'w') : nil @loop_wl1 = @loop_wl2 = nil @ruby_arg = opt[:ruby_arg] || nil @opt = opt @@ -148,12 +147,27 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L147 message "Elapsed time: #{Time.now - @start_time} (sec)" end - if @rawdata_output + if rawdata_output = @opt[:rawdata_output] h = {} h[:cpuinfo] = File.read('/proc/cpuinfo') if File.exist?('/proc/cpuinfo') h[:executables] = @execs h[:results] = @results - @rawdata_output.puts h.inspect + if (type = File.extname(rawdata_output)).empty? + type = rawdata_output + rawdata_output = @output.path.sub(/\.[^.\/]+\z/, '') << '.' << rawdata_output + end + case type + when 'yaml' + require 'yaml' + h = YAML.dump(h) + when 'json' + require 'json' + h = JSON.pretty_generate(h) + else + require 'pp' + h = h.pretty_inspect + end + open(rawdata_output, 'w') {|f| f.puts h} end output '-----------------------------------------------------------' -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/