ruby-changes:2054
From: ko1@a...
Date: 28 Sep 2007 16:00:23 +0900
Subject: [ruby-changes:2054] ko1 - Ruby:r13545 (trunk): * benchmark/driver.rb: fix to output benchmark results
ko1 2007-09-28 15:59:59 +0900 (Fri, 28 Sep 2007) New Revision: 13545 Added files: trunk/benchmark/bm_vm2_eval.rb Modified files: trunk/ChangeLog trunk/benchmark/bm_io_file_create.rb trunk/benchmark/driver.rb Log: * benchmark/driver.rb: fix to output benchmark results to file "bmlog-#{Time.now.strftime('%Y%m%d-%H%M%S')}.#{$$}". * benchmark/bm_io_file_create.rb: remove useless codes. * benchmark/bm_vm2_eval.rb: added. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/benchmark/driver.rb?r1=13545&r2=13544 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13545&r2=13544 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/benchmark/bm_vm2_eval.rb?revision=13545&view=markup http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/benchmark/bm_io_file_create.rb?r1=13545&r2=13544 Index: ChangeLog =================================================================== --- ChangeLog (revision 13544) +++ ChangeLog (revision 13545) @@ -1,3 +1,12 @@ +Fri Sep 28 15:47:48 2007 Koichi Sasada <ko1@a...> + + * benchmark/driver.rb: fix to output benchmark results + to file "bmlog-#{Time.now.strftime('%Y%m%d-%H%M%S')}.#{$$}". + + * benchmark/bm_io_file_create.rb: remove useless codes. + + * benchmark/bm_vm2_eval.rb: added. + Fri Sep 28 15:05:24 2007 Tanaka Akira <akr@f...> * include/ruby/intern.h: export rb_ivar_foreach. Index: benchmark/driver.rb =================================================================== --- benchmark/driver.rb (revision 13544) +++ benchmark/driver.rb (revision 13545) @@ -16,6 +16,30 @@ end end + def output *args + puts(*args) + @output and @output.puts(*args) + end + + def message *args + output(*args) if @verbose + end + + def message_print *args + if @verbose + print(*args) + STDOUT.flush + @output and @output.print(*args) + end + end + + def progress_message *args + unless STDOUT.tty? + STDERR.print(*args) + STDERR.flush + end + end + def initialize execs, dir, opt = {} @execs = execs.map{|e| e.strip! @@ -31,6 +55,7 @@ @repeat = 1 if @repeat < 1 @pattern = opt[:pattern] || nil @verbose = opt[:quiet] ? false : (opt[:verbose] || false) + @output = opt[:output] ? open(opt[:output], 'w') : nil @loop_wl1 = @loop_wl2 = nil @opt = opt @@ -39,32 +64,32 @@ if @verbose @start_time = Time.now - puts @start_time + message @start_time @execs.each_with_index{|(e, v), i| - puts "target #{i}: #{v}" + message "target #{i}: #{v}" } end end def show_results - puts + output + if @verbose - puts '-----------------------------------------------------------' - puts 'raw data:' - pp @results - - puts - puts "Elapesed time: #{Time.now - @start_time} (sec)" + message '-----------------------------------------------------------' + message 'raw data:' + message PP.pp(@results, "", 79) + message + message "Elapesed time: #{Time.now - @start_time} (sec)" end - puts '-----------------------------------------------------------' - puts 'benchmark results:' + output '-----------------------------------------------------------' + output 'benchmark results:' if @verbose and @repeat > 1 - puts "minimum results in each #{@repeat} measurements." + output "minimum results in each #{@repeat} measurements." end - puts "name\t#{@execs.map{|(e, v)| v}.join("\t")}" + output "name\t#{@execs.map{|(e, v)| v}.join("\t")}" @results.each{|v, result| rets = [] s = nil @@ -84,9 +109,8 @@ end rets << sprintf("%.3f", r) } - puts "#{v}#{s}\t#{rets.join("\t")}" + output "#{v}#{s}\t#{rets.join("\t")}" } - end def files @@ -108,7 +132,7 @@ end @files.sort! - STDERR.puts "total: #{@files.size * @repeat} trial(s) (#{@repeat} trial(s) for #{@files.size} benchmark(s))" + progress_message "total: #{@files.size * @repeat} trial(s) (#{@repeat} trial(s) for #{@files.size} benchmark(s))\n" @files end @@ -131,28 +155,21 @@ load prepare_file if FileTest.exist?(prepare_file) if @verbose - puts - puts '-----------------------------------------------------------' - puts name - puts File.read(file) - puts + output + output '-----------------------------------------------------------' + output name + output File.read(file) + output end result = [name] result << @execs.map{|(e, v)| (0...@repeat).map{ - if @verbose - print "#{v}\t" - STDOUT.flush - end + message_print "#{v}\t" + progress_message '.' - if !@verbose || !STDOUT.tty? - STDERR.print '.' - STDERR.flush - end - - m = measure e, file - puts "#{m}" if @verbose + m = measure(e, file) + message "#{m}" m } } @@ -161,7 +178,6 @@ end def measure executable, file - cmd = "#{executable} #{file}" m = Benchmark.measure{ `#{cmd}` @@ -170,6 +186,7 @@ if $? != 0 raise "Benchmark process exited with abnormal status (#{$?})" end + m.real end end @@ -179,13 +196,15 @@ :execs => ['ruby'], :dir => './', :repeat => 1, + :output => "bmlog-#{Time.now.strftime('%Y%m%d-%H%M%S')}.#{$$}", } + parser = OptionParser.new{|o| o.on('-e', '--executables [EXECS]', "Specify benchmark one or more targets. (exec1; exec2; exec3, ...)"){|e| opt[:execs] = e.split(/;/) } - o.on('-d', '--directory [DIRECTORY]', "Benchmark directory"){|d| + o.on('-d', '--directory [DIRECTORY]', "Benchmark suites directory"){|d| opt[:dir] = d } o.on('-p', '--pattern [PATTERN]', "Benchmark name pattern"){|p| @@ -194,6 +213,9 @@ o.on('-r', '--repeat-count [NUM]', "Repeat count"){|n| opt[:repeat] = n.to_i } + o.on('-o', '--output-file [FILE]', "Output file"){|o| + opt[:output] = o + } o.on('-q', '--quiet', "Run without notify information except result table."){|q| opt[:quiet] = q } Index: benchmark/bm_vm2_eval.rb =================================================================== --- benchmark/bm_vm2_eval.rb (revision 0) +++ benchmark/bm_vm2_eval.rb (revision 13545) @@ -0,0 +1,6 @@ +i=0 +while i<6000000 # benchmark loop 2 + i+=1 + eval("1") +end + Index: benchmark/bm_io_file_create.rb =================================================================== --- benchmark/bm_io_file_create.rb (revision 13544) +++ benchmark/bm_io_file_create.rb (revision 13545) @@ -2,13 +2,10 @@ # Create files # -require 'tempfile' - max = 50_000 file = './tmpfile_of_bm_io_file_create' max.times{ - #f = Tempfile.new('yarv-benchmark') f = open(file, 'w') f.close#(true) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml