From 8aa618d8e27e9728b6d102bf69e3294d7e9283e6 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 28 Sep 2007 06:59:59 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++ benchmark/bm_io_file_create.rb | 3 -- benchmark/bm_vm2_eval.rb | 6 +++ benchmark/driver.rb | 90 ++++++++++++++++++++++++++---------------- 4 files changed, 71 insertions(+), 37 deletions(-) create mode 100644 benchmark/bm_vm2_eval.rb diff --git a/ChangeLog b/ChangeLog index d629a4c281..3c694f163c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Sep 28 15:47:48 2007 Koichi Sasada + + * 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 * include/ruby/intern.h: export rb_ivar_foreach. diff --git a/benchmark/bm_io_file_create.rb b/benchmark/bm_io_file_create.rb index 3b48028808..db4e4dedd2 100644 --- a/benchmark/bm_io_file_create.rb +++ b/benchmark/bm_io_file_create.rb @@ -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) } diff --git a/benchmark/bm_vm2_eval.rb b/benchmark/bm_vm2_eval.rb new file mode 100644 index 0000000000..9ab781edd4 --- /dev/null +++ b/benchmark/bm_vm2_eval.rb @@ -0,0 +1,6 @@ +i=0 +while i<6000000 # benchmark loop 2 + i+=1 + eval("1") +end + diff --git a/benchmark/driver.rb b/benchmark/driver.rb index 56c3efff0e..cb5a6d3734 100644 --- a/benchmark/driver.rb +++ b/benchmark/driver.rb @@ -16,6 +16,30 @@ class BenchmarkDriver 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 @@ class BenchmarkDriver @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 @@ class BenchmarkDriver 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 - if @verbose - puts '-----------------------------------------------------------' - puts 'raw data:' - pp @results + output - puts - puts "Elapesed time: #{Time.now - @start_time} (sec)" + if @verbose + 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 @@ class BenchmarkDriver 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 @@ class BenchmarkDriver 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 @@ class BenchmarkDriver 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 - - if !@verbose || !STDOUT.tty? - STDERR.print '.' - STDERR.flush - end + message_print "#{v}\t" + progress_message '.' - m = measure e, file - puts "#{m}" if @verbose + m = measure(e, file) + message "#{m}" m } } @@ -161,7 +178,6 @@ class BenchmarkDriver end def measure executable, file - cmd = "#{executable} #{file}" m = Benchmark.measure{ `#{cmd}` @@ -170,6 +186,7 @@ class BenchmarkDriver if $? != 0 raise "Benchmark process exited with abnormal status (#{$?})" end + m.real end end @@ -179,13 +196,15 @@ if __FILE__ == $0 :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 @@ if __FILE__ == $0 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 } -- cgit v1.2.3