* 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
This commit is contained in:
ko1 2007-09-28 06:59:59 +00:00
Родитель 37f9d089ed
Коммит 8aa618d8e2
4 изменённых файлов: 71 добавлений и 37 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Fri Sep 28 15:47:48 2007 Koichi Sasada <ko1@atdot.net>
* 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@fsij.org> Fri Sep 28 15:05:24 2007 Tanaka Akira <akr@fsij.org>
* include/ruby/intern.h: export rb_ivar_foreach. * include/ruby/intern.h: export rb_ivar_foreach.

Просмотреть файл

@ -2,13 +2,10 @@
# Create files # Create files
# #
require 'tempfile'
max = 50_000 max = 50_000
file = './tmpfile_of_bm_io_file_create' file = './tmpfile_of_bm_io_file_create'
max.times{ max.times{
#f = Tempfile.new('yarv-benchmark')
f = open(file, 'w') f = open(file, 'w')
f.close#(true) f.close#(true)
} }

6
benchmark/bm_vm2_eval.rb Normal file
Просмотреть файл

@ -0,0 +1,6 @@
i=0
while i<6000000 # benchmark loop 2
i+=1
eval("1")
end

Просмотреть файл

@ -16,6 +16,30 @@ class BenchmarkDriver
end end
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 = {} def initialize execs, dir, opt = {}
@execs = execs.map{|e| @execs = execs.map{|e|
e.strip! e.strip!
@ -31,6 +55,7 @@ class BenchmarkDriver
@repeat = 1 if @repeat < 1 @repeat = 1 if @repeat < 1
@pattern = opt[:pattern] || nil @pattern = opt[:pattern] || nil
@verbose = opt[:quiet] ? false : (opt[:verbose] || false) @verbose = opt[:quiet] ? false : (opt[:verbose] || false)
@output = opt[:output] ? open(opt[:output], 'w') : nil
@loop_wl1 = @loop_wl2 = nil @loop_wl1 = @loop_wl2 = nil
@opt = opt @opt = opt
@ -39,32 +64,32 @@ class BenchmarkDriver
if @verbose if @verbose
@start_time = Time.now @start_time = Time.now
puts @start_time message @start_time
@execs.each_with_index{|(e, v), i| @execs.each_with_index{|(e, v), i|
puts "target #{i}: #{v}" message "target #{i}: #{v}"
} }
end end
end end
def show_results def show_results
puts output
if @verbose
puts '-----------------------------------------------------------'
puts 'raw data:'
pp @results
puts if @verbose
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 end
puts '-----------------------------------------------------------' output '-----------------------------------------------------------'
puts 'benchmark results:' output 'benchmark results:'
if @verbose and @repeat > 1 if @verbose and @repeat > 1
puts "minimum results in each #{@repeat} measurements." output "minimum results in each #{@repeat} measurements."
end 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| @results.each{|v, result|
rets = [] rets = []
s = nil s = nil
@ -84,9 +109,8 @@ class BenchmarkDriver
end end
rets << sprintf("%.3f", r) rets << sprintf("%.3f", r)
} }
puts "#{v}#{s}\t#{rets.join("\t")}" output "#{v}#{s}\t#{rets.join("\t")}"
} }
end end
def files def files
@ -108,7 +132,7 @@ class BenchmarkDriver
end end
@files.sort! @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 @files
end end
@ -131,28 +155,21 @@ class BenchmarkDriver
load prepare_file if FileTest.exist?(prepare_file) load prepare_file if FileTest.exist?(prepare_file)
if @verbose if @verbose
puts output
puts '-----------------------------------------------------------' output '-----------------------------------------------------------'
puts name output name
puts File.read(file) output File.read(file)
puts output
end end
result = [name] result = [name]
result << @execs.map{|(e, v)| result << @execs.map{|(e, v)|
(0...@repeat).map{ (0...@repeat).map{
if @verbose message_print "#{v}\t"
print "#{v}\t" progress_message '.'
STDOUT.flush
end
if !@verbose || !STDOUT.tty? m = measure(e, file)
STDERR.print '.' message "#{m}"
STDERR.flush
end
m = measure e, file
puts "#{m}" if @verbose
m m
} }
} }
@ -161,7 +178,6 @@ class BenchmarkDriver
end end
def measure executable, file def measure executable, file
cmd = "#{executable} #{file}" cmd = "#{executable} #{file}"
m = Benchmark.measure{ m = Benchmark.measure{
`#{cmd}` `#{cmd}`
@ -170,6 +186,7 @@ class BenchmarkDriver
if $? != 0 if $? != 0
raise "Benchmark process exited with abnormal status (#{$?})" raise "Benchmark process exited with abnormal status (#{$?})"
end end
m.real m.real
end end
end end
@ -179,13 +196,15 @@ if __FILE__ == $0
:execs => ['ruby'], :execs => ['ruby'],
:dir => './', :dir => './',
:repeat => 1, :repeat => 1,
:output => "bmlog-#{Time.now.strftime('%Y%m%d-%H%M%S')}.#{$$}",
} }
parser = OptionParser.new{|o| parser = OptionParser.new{|o|
o.on('-e', '--executables [EXECS]', o.on('-e', '--executables [EXECS]',
"Specify benchmark one or more targets. (exec1; exec2; exec3, ...)"){|e| "Specify benchmark one or more targets. (exec1; exec2; exec3, ...)"){|e|
opt[:execs] = e.split(/;/) opt[:execs] = e.split(/;/)
} }
o.on('-d', '--directory [DIRECTORY]', "Benchmark directory"){|d| o.on('-d', '--directory [DIRECTORY]', "Benchmark suites directory"){|d|
opt[:dir] = d opt[:dir] = d
} }
o.on('-p', '--pattern [PATTERN]', "Benchmark name pattern"){|p| 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| o.on('-r', '--repeat-count [NUM]', "Repeat count"){|n|
opt[:repeat] = n.to_i 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| o.on('-q', '--quiet', "Run without notify information except result table."){|q|
opt[:quiet] = q opt[:quiet] = q
} }