2 # Ruby benchmark driver
15 wcinput = File.join(File.dirname($0), 'wc.input')
16 wcbase = File.join(File.dirname($0), 'wc.input.base')
17 unless FileTest.exist?(wcinput)
18 data = File.read(wcbase)
22 open(wcinput, 'w'){|f| f.write data}
29 prog = File.readlines(file).map{|e| e.rstrip}.join("\n")
32 /[a-z]+_(.+)\.rb/ =~ file
34 puts '-----------------------------------------------------------' unless $rubyonly || $matzrubyonly
38 puts <<EOS unless $matzrubyonly || $rubyonly
44 result << matzruby_exec(file) unless $rubyonly
45 result << ruby_exec(file) unless $matzrubyonly
50 puts "** benchmark failure: #{e}"
55 def benchmark file, bin
56 m = Benchmark.measure{
57 `#{bin} #{$opts} #{file}`
66 benchmark file, $ruby_program
69 def matzruby_exec file
71 rubylib = ENV['RUBYLIB']
73 r = benchmark file, $matzruby_program
74 ENV['RUBYLIB'] = rubylib
83 when /\A--matzruby=(.+)/
84 $matzruby_program = $1
87 when /\A(-r|--only-ruby)\z/
89 when /\A(-m|--only-matzruby)\z/
98 system("#{$matzruby_program} -v")
100 system("#{$ruby_program} -v")
104 Dir.glob(File.dirname(__FILE__) + '/bm_*.rb').sort.each{|file|
109 Dir.glob(File.join(File.dirname(__FILE__), file + '*')){|ef|
110 # file = "#{File.dirname(__FILE__)}/#{file}.rb"
117 puts "-- benchmark summary ---------------------------"
119 print res.shift, "\t"
120 (res||[]).each{|result|
121 /([\d\.]+)/ =~ result
122 print $1 + "\t" if $1