1# 2# YARV benchmark driver 3# 4 5require 'yarvutil' 6require 'benchmark' 7require 'rbconfig' 8 9def exec_command type, file, w 10 <<-EOP 11 $DRIVER_PATH = '#{File.dirname($0)}' 12 $LOAD_PATH.replace $LOAD_PATH | #{$LOAD_PATH.inspect} 13 require 'benchmark' 14 require 'yarvutil' 15# print '#{type}' 16 begin 17 puts Benchmark.measure{ 18 #{w}('#{file}') 19 }.utime 20 rescue Exception => exec_command_error_variable 21 puts "\t" + exec_command_error_variable.message 22 end 23 EOP 24end 25 26def benchmark cmd 27 rubybin = ENV['RUBY'] || RbConfig.ruby 28 29 IO.popen(rubybin, 'r+'){|io| 30 io.write cmd 31 io.close_write 32 return io.gets 33 } 34end 35 36def ruby_exec file 37 prog = exec_command 'ruby', file, 'load' 38 benchmark prog 39end 40 41def yarv_exec file 42 prog = exec_command 'yarv', file, 'YARVUtil.load_bm' 43 benchmark prog 44end 45 46$wr = $wy = nil 47 48def measure bench 49 file = File.dirname($0) + "/bm_#{bench}.rb" 50 r = ruby_exec(file).to_f 51 y = yarv_exec(file).to_f 52 puts "#{bench}\t#{r}\t#{y}" 53end 54 55def measure2 56 r = ruby_exec.to_f 57 y = yarv_exec.to_f 58 puts r/y 59end 60 61if $0 == __FILE__ 62 %w{ 63 whileloop 64 whileloop2 65 times 66 const 67 method 68 poly_method 69 block 70 rescue 71 rescue2 72 }.each{|bench| 73 measure bench 74 } 75end 76 77 78 79 80