summaryrefslogtreecommitdiff
path: root/benchmark/driver.rb
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 06:59:59 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 06:59:59 +0000
commit8aa618d8e27e9728b6d102bf69e3294d7e9283e6 (patch)
treec8da9a224aa49e4a37596be3a4888fdf78538c63 /benchmark/driver.rb
parent37f9d089ed30477e1f7d8c54fde6047e7c1d3154 (diff)
* 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
Diffstat (limited to 'benchmark/driver.rb')
-rw-r--r--benchmark/driver.rb90
1 files changed, 56 insertions, 34 deletions
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
}