mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* benchmark/bm_app_pentomino.rb : use Array#dup instead of
Array#clone * benchmark/bmx_temp.rb : removed * benchmark/run.rb : use run.rb instead of run_rite.rb * common.mk : ditto * benchmark/run_rite.rb : removed * common.mk : use $(srcdir)/test.rb to run a test program with "make run" * benchmark/bmx_temp.rb : removed and set svn:ignore (bmx_*.rb) to benchmark/ * test.rb : set svn:ignore git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									c5a0c3be2e
								
							
						
					
					
						commit
						d22d3b5a7a
					
				
					 7 changed files with 80 additions and 254 deletions
				
			
		| 
						 | 
				
			
			@ -18,7 +18,7 @@ def piece(n, a, nb)
 | 
			
		|||
    if n == NP-1
 | 
			
		||||
      $p << [a.sort]
 | 
			
		||||
    else
 | 
			
		||||
      nbc=nb.clone
 | 
			
		||||
      nbc=nb.dup
 | 
			
		||||
      [-ROW, -1, 1, ROW].each{|d|
 | 
			
		||||
        if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
 | 
			
		||||
          nbc << x+d
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +113,7 @@ def setpiece(a,pos)
 | 
			
		|||
          $b[pos+s] = i
 | 
			
		||||
        }
 | 
			
		||||
        a << i
 | 
			
		||||
        setpiece(a.clone, pos)
 | 
			
		||||
        setpiece(a.dup, pos)
 | 
			
		||||
        a.pop
 | 
			
		||||
        x.each{|s|
 | 
			
		||||
          $b[pos+s] = -1
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +148,7 @@ def piece(n,a,nb)
 | 
			
		|||
    if n == NP-1
 | 
			
		||||
      $p << [a.sort]
 | 
			
		||||
    else
 | 
			
		||||
      nbc=nb.clone
 | 
			
		||||
      nbc=nb.dup
 | 
			
		||||
      for d in [-ROW, -1, 1, ROW]
 | 
			
		||||
        if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
 | 
			
		||||
          nbc << x+d
 | 
			
		||||
| 
						 | 
				
			
			@ -242,7 +242,7 @@ def setpiece(a,pos)
 | 
			
		|||
          $b[pos+s] = i
 | 
			
		||||
        end
 | 
			
		||||
        a << i
 | 
			
		||||
        setpiece(a.clone, pos)
 | 
			
		||||
        setpiece(a.dup, pos)
 | 
			
		||||
        a.pop
 | 
			
		||||
        for s in x do
 | 
			
		||||
          $b[pos+s] = -1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,57 +0,0 @@
 | 
			
		|||
 | 
			
		||||
i=0
 | 
			
		||||
while i<20000000
 | 
			
		||||
  x = 1 # "foo"
 | 
			
		||||
  i+=1
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
__END__
 | 
			
		||||
 | 
			
		||||
class Range
 | 
			
		||||
  def each
 | 
			
		||||
    f = self.first
 | 
			
		||||
    l = self.last
 | 
			
		||||
    while f < l
 | 
			
		||||
      yield
 | 
			
		||||
      f = f.succ
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
(0..10000000).each{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__END__
 | 
			
		||||
class Fixnum_
 | 
			
		||||
  def times
 | 
			
		||||
    i = 0
 | 
			
		||||
    while i<self
 | 
			
		||||
      yield(i)
 | 
			
		||||
      i+=1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
10000000.times{
 | 
			
		||||
}
 | 
			
		||||
__END__
 | 
			
		||||
 | 
			
		||||
ths = (1..10).map{
 | 
			
		||||
  Thread.new{
 | 
			
		||||
    1000000.times{
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
ths.each{|e|
 | 
			
		||||
  e.join
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__END__
 | 
			
		||||
$pr = proc{}
 | 
			
		||||
def m
 | 
			
		||||
  $pr.call
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
1000000.times{|e|
 | 
			
		||||
  m
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
# YARV benchmark driver
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'yarvutil'
 | 
			
		||||
require 'benchmark'
 | 
			
		||||
require 'rbconfig'
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -11,13 +10,23 @@ $rubyonly = false
 | 
			
		|||
 | 
			
		||||
$results  = []
 | 
			
		||||
 | 
			
		||||
puts "ruby #{RUBY_VERSION} #{RUBY_PLATFORM}(#{RUBY_RELEASE_DATE})"
 | 
			
		||||
puts YARVCore::VERSION + " rev: #{YARVCore::REV} (#{YARVCore::DATE})"
 | 
			
		||||
puts YARVCore::OPTS
 | 
			
		||||
puts
 | 
			
		||||
# prepare 'wc.input'
 | 
			
		||||
def prepare_wc_input
 | 
			
		||||
  wcinput = File.join(File.dirname($0), 'wc.input')
 | 
			
		||||
  wcbase  = File.join(File.dirname($0), 'wc.input.base')
 | 
			
		||||
  unless FileTest.exist?(wcinput)
 | 
			
		||||
    data = File.read(wcbase)
 | 
			
		||||
    13.times{
 | 
			
		||||
      data << data
 | 
			
		||||
    }
 | 
			
		||||
    open(wcinput, 'w'){|f| f.write data}
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
prepare_wc_input
 | 
			
		||||
 | 
			
		||||
def bm file
 | 
			
		||||
  prog = File.read(file).map{|e| e.rstrip}.join("\n")
 | 
			
		||||
  prog = File.readlines(file).map{|e| e.rstrip}.join("\n")
 | 
			
		||||
  return if prog.empty?
 | 
			
		||||
 | 
			
		||||
  /[a-z]+_(.+)\.rb/ =~ file
 | 
			
		||||
| 
						 | 
				
			
			@ -33,10 +42,6 @@ EOS
 | 
			
		|||
  #iseq = YARVUtil.parse(File.read(file))
 | 
			
		||||
  #vm   = YARVCore::VM.new
 | 
			
		||||
  begin
 | 
			
		||||
    Benchmark.bm{|x|
 | 
			
		||||
    # x.report("yarv"){ YARVUtil.load_bm(file) }
 | 
			
		||||
    } unless $yarvonly || $rubyonly
 | 
			
		||||
 | 
			
		||||
    result = [bm_name]
 | 
			
		||||
    result << ruby_exec(file) unless $yarvonly
 | 
			
		||||
    result << yarv_exec(file) unless $rubyonly
 | 
			
		||||
| 
						 | 
				
			
			@ -53,55 +58,37 @@ EOS
 | 
			
		|||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def exec_command type, file, w
 | 
			
		||||
  <<-EOP
 | 
			
		||||
  $DRIVER_PATH = '#{File.dirname($0)}'
 | 
			
		||||
  $LOAD_PATH.replace $LOAD_PATH | #{$LOAD_PATH.inspect}
 | 
			
		||||
  require 'benchmark'
 | 
			
		||||
  require 'yarvutil'
 | 
			
		||||
  print '#{type}'
 | 
			
		||||
  begin
 | 
			
		||||
    puts Benchmark.measure{
 | 
			
		||||
      #{w}('#{file}')
 | 
			
		||||
    }
 | 
			
		||||
  rescue Exception => exec_command_error_variable
 | 
			
		||||
    puts "\t" + exec_command_error_variable.message
 | 
			
		||||
  end
 | 
			
		||||
  EOP
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def benchmark prog
 | 
			
		||||
  rubybin = ENV['RUBY'] || File.join(
 | 
			
		||||
    Config::CONFIG["bindir"],
 | 
			
		||||
    Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"])
 | 
			
		||||
 | 
			
		||||
  #
 | 
			
		||||
  tmpfile = Tempfile.new('yarvbench')
 | 
			
		||||
  tmpfile.write(prog)
 | 
			
		||||
  tmpfile.close
 | 
			
		||||
 | 
			
		||||
  cmd = "#{rubybin} #{tmpfile.path}"
 | 
			
		||||
  result = `#{cmd}`
 | 
			
		||||
  puts result
 | 
			
		||||
  tmpfile.close(true)
 | 
			
		||||
  result
 | 
			
		||||
def benchmark file, bin
 | 
			
		||||
  m = Benchmark.measure{
 | 
			
		||||
    `#{bin} #{$opts} #{file}`
 | 
			
		||||
  }
 | 
			
		||||
  sec = '%.3f' % m.real
 | 
			
		||||
  puts " #{sec}"
 | 
			
		||||
  sec
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def ruby_exec file
 | 
			
		||||
  prog = exec_command 'ruby', file, 'load'
 | 
			
		||||
  benchmark prog
 | 
			
		||||
  print 'ruby'
 | 
			
		||||
  benchmark file, $ruby_program
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def yarv_exec file
 | 
			
		||||
  prog = exec_command 'yarv', file, 'YARVUtil.load_bm'
 | 
			
		||||
  benchmark prog
 | 
			
		||||
  print 'yarv'
 | 
			
		||||
  benchmark file, $yarv_program
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if $0 == __FILE__
 | 
			
		||||
  ARGV.each{|arg|
 | 
			
		||||
    if /\A(--yarv)|(-y)/ =~ arg
 | 
			
		||||
    case arg
 | 
			
		||||
    when /\A--yarv-program=(.+)/
 | 
			
		||||
      $yarv_program = $1
 | 
			
		||||
    when /\A--ruby-program=(.+)/
 | 
			
		||||
      $ruby_program = $1
 | 
			
		||||
    when /\A--opts=(.+)/
 | 
			
		||||
      $opts = $1
 | 
			
		||||
    when /\A(--yarv)|(-y)/
 | 
			
		||||
      $yarvonly = true
 | 
			
		||||
    elsif /\A(--ruby)|(-r)/ =~ arg
 | 
			
		||||
    when /\A(--ruby)|(-r)/
 | 
			
		||||
      $rubyonly = true
 | 
			
		||||
    end
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -109,6 +96,12 @@ if $0 == __FILE__
 | 
			
		|||
    /\A-/ =~ arg
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  puts "Ruby:"
 | 
			
		||||
  system("#{$ruby_program} -v")
 | 
			
		||||
  puts
 | 
			
		||||
  puts "YARV:"
 | 
			
		||||
  system("#{$yarv_program} -v")
 | 
			
		||||
 | 
			
		||||
  if ARGV.empty?
 | 
			
		||||
    Dir.glob(File.dirname(__FILE__) + '/bm_*.rb').sort.each{|file|
 | 
			
		||||
      bm file
 | 
			
		||||
| 
						 | 
				
			
			@ -134,4 +127,3 @@ if $0 == __FILE__
 | 
			
		|||
  }
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,129 +0,0 @@
 | 
			
		|||
#
 | 
			
		||||
# YARV benchmark driver
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
require 'benchmark'
 | 
			
		||||
require 'rbconfig'
 | 
			
		||||
 | 
			
		||||
$yarvonly = false
 | 
			
		||||
$rubyonly = false
 | 
			
		||||
 | 
			
		||||
$results  = []
 | 
			
		||||
 | 
			
		||||
# prepare 'wc.input'
 | 
			
		||||
def prepare_wc_input
 | 
			
		||||
  wcinput = File.join(File.dirname($0), 'wc.input')
 | 
			
		||||
  wcbase  = File.join(File.dirname($0), 'wc.input.base')
 | 
			
		||||
  unless FileTest.exist?(wcinput)
 | 
			
		||||
    data = File.read(wcbase)
 | 
			
		||||
    13.times{
 | 
			
		||||
      data << data
 | 
			
		||||
    }
 | 
			
		||||
    open(wcinput, 'w'){|f| f.write data}
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
prepare_wc_input
 | 
			
		||||
 | 
			
		||||
def bm file
 | 
			
		||||
  prog = File.readlines(file).map{|e| e.rstrip}.join("\n")
 | 
			
		||||
  return if prog.empty?
 | 
			
		||||
 | 
			
		||||
  /[a-z]+_(.+)\.rb/ =~ file
 | 
			
		||||
  bm_name = $1
 | 
			
		||||
  puts '-----------------------------------------------------------' unless $yarvonly || $rubyonly
 | 
			
		||||
  puts "#{bm_name}: "
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
puts <<EOS unless $yarvonly || $rubyonly
 | 
			
		||||
#{prog}
 | 
			
		||||
--
 | 
			
		||||
EOS
 | 
			
		||||
  #iseq = YARVUtil.parse(File.read(file))
 | 
			
		||||
  #vm   = YARVCore::VM.new
 | 
			
		||||
  begin
 | 
			
		||||
    result = [bm_name]
 | 
			
		||||
    result << ruby_exec(file) unless $yarvonly
 | 
			
		||||
    result << yarv_exec(file) unless $rubyonly
 | 
			
		||||
    $results << result
 | 
			
		||||
    
 | 
			
		||||
    # puts YARVUtil.parse(File.read(file), file, 1).disasm
 | 
			
		||||
    
 | 
			
		||||
    # x.report("ruby"){ load(file, false)    }
 | 
			
		||||
    # x.report("yarv"){ vm.eval iseq }
 | 
			
		||||
  rescue Exception => e
 | 
			
		||||
    puts
 | 
			
		||||
    puts "** benchmark failure: #{e}"
 | 
			
		||||
    puts e.backtrace
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def benchmark file, bin
 | 
			
		||||
  m = Benchmark.measure{
 | 
			
		||||
    `#{bin} #{$opts} #{file}`
 | 
			
		||||
  }
 | 
			
		||||
  sec = '%.3f' % m.real
 | 
			
		||||
  puts " #{sec}"
 | 
			
		||||
  sec
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def ruby_exec file
 | 
			
		||||
  print 'ruby'
 | 
			
		||||
  benchmark file, $ruby_program
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def yarv_exec file
 | 
			
		||||
  print 'yarv'
 | 
			
		||||
  benchmark file, $yarv_program
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if $0 == __FILE__
 | 
			
		||||
  ARGV.each{|arg|
 | 
			
		||||
    case arg
 | 
			
		||||
    when /\A--yarv-program=(.+)/
 | 
			
		||||
      $yarv_program = $1
 | 
			
		||||
    when /\A--ruby-program=(.+)/
 | 
			
		||||
      $ruby_program = $1
 | 
			
		||||
    when /\A--opts=(.+)/
 | 
			
		||||
      $opts = $1
 | 
			
		||||
    when /\A(--yarv)|(-y)/
 | 
			
		||||
      $yarvonly = true
 | 
			
		||||
    when /\A(--ruby)|(-r)/
 | 
			
		||||
      $rubyonly = true
 | 
			
		||||
    end
 | 
			
		||||
  }
 | 
			
		||||
  ARGV.delete_if{|arg|
 | 
			
		||||
    /\A-/ =~ arg
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  puts "Ruby:"
 | 
			
		||||
  system("#{$ruby_program} -v")
 | 
			
		||||
  puts
 | 
			
		||||
  puts "YARV:"
 | 
			
		||||
  system("#{$yarv_program} -v")
 | 
			
		||||
 | 
			
		||||
  if ARGV.empty?
 | 
			
		||||
    Dir.glob(File.dirname(__FILE__) + '/bm_*.rb').sort.each{|file|
 | 
			
		||||
      bm file
 | 
			
		||||
    }
 | 
			
		||||
  else
 | 
			
		||||
    ARGV.each{|file|
 | 
			
		||||
      Dir.glob(File.join(File.dirname(__FILE__), file + '*')){|ef|
 | 
			
		||||
        # file = "#{File.dirname(__FILE__)}/#{file}.rb"
 | 
			
		||||
        bm ef
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  puts
 | 
			
		||||
  puts "-- benchmark summary ---------------------------"
 | 
			
		||||
  $results.each{|res|
 | 
			
		||||
    print res.shift, "\t"
 | 
			
		||||
    (res||[]).each{|result|
 | 
			
		||||
      /([\d\.]+)/ =~ result
 | 
			
		||||
      print $1 + "\t" if $1
 | 
			
		||||
    }
 | 
			
		||||
    puts
 | 
			
		||||
  }
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue