/usr/local/bin/ruby_cyg19 -I.. ../benchmark/run.rb ruby 1.9.0 i386-cygwin(2004-11-29) YARVCore Ver.0.0.0.f [direct threaded code] [optimize basic operation] [optimize regexp match] [rev: 82 (2004-12-06)] ----------------------------------------------------------- block: class Array def each_ len = self.length i = 0 while i 1) n * fact(n-1) else 1 end end fact(7300) -- user system total real ruby 0.672000 0.125000 0.797000 ( 4.474000) yarv 0.516000 0.015000 0.531000 ( 0.534000) ----------------------------------------------------------- fib: def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(32) -- user system total real ruby 5.500000 0.000000 5.500000 ( 5.494000) yarv 0.937000 0.000000 0.937000 ( 0.938000) ----------------------------------------------------------- lists: #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby NUM = 100 SIZE = 10000 def test_lists() # create a list of integers (Li1) from 1 to SIZE li1 = Array.new(SIZE){|i| i+1} # (1..SIZE).to_a # copy the list to li2 (not by individual items) li2 = li1.dup # remove each individual item from left side of li2 and # append to right side of li3 (preserving order) li3 = Array.new while (not li2.empty?) li3.push(li2.shift) end # li2 must now be empty # remove each individual item from right side of li3 and # append to right side of li2 (reversing list) while (not li3.empty?) li2.push(li3.pop) end # li3 must now be empty # reverse li1 in place li1.reverse! # check that first item is now SIZE if li1[0] != SIZE then p "not SIZE" 0 else # compare li1 and li2 for equality if li1 != li2 then return(0) else # return the length of the list li1.length end end end i = 0 while i 1 1 + reccount(n-1) else 1 end end reccount 7000 -- user system total real ruby 0.079000 0.078000 0.157000 ( 0.156000) yarv 0.016000 0.000000 0.016000 ( 0.006000) ----------------------------------------------------------- regexp: i=0 while i<1000000 /hoge/ =~ 'xxxhogexxx' i+=1 end -- user system total real ruby 1.969000 0.000000 1.969000 ( 1.991000) yarv 1.188000 0.000000 1.188000 ( 1.205000) ----------------------------------------------------------- rescue: i=0 while i<1000000 i+=1 begin begin rescue end rescue # ensure end end -- user system total real ruby 1.000000 0.000000 1.000000 ( 0.992000) yarv 0.140000 0.000000 0.140000 ( 0.134000) ----------------------------------------------------------- simpleiter: 1000000.times{|simpleiter| simpleiter } -- user system total real ruby 0.484000 0.000000 0.484000 ( 0.496000) yarv 0.187000 0.000000 0.187000 ( 0.191000) ----------------------------------------------------------- simplereturn: def m return 1 end i=0 while i<1000000 i+=1 m end -- user system total real ruby 1.094000 0.000000 1.094000 ( 1.095000) yarv 0.234000 0.000000 0.234000 ( 0.232000) ----------------------------------------------------------- so_ackermann: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ def ack(m, n) if m == 0 then n + 1 elsif n == 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end NUM = 7 ack(3, NUM) -- user system total real ruby 3.953000 0.047000 4.000000 ( 3.996000) yarv 0.266000 0.015000 0.281000 ( 0.255000) ----------------------------------------------------------- so_array: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Paul Brannan and Mark Hubbart n = 9000 # Integer(ARGV.shift || 1) x = Array.new(n) y = Array.new(n, 0) n.times{|bi| x[bi] = bi + 1 } (0 .. 999).each do |e| (n-1).step(0,-1) do |bi| y[bi] += x.at(bi) end end # puts "#{y.first} #{y.last}" -- user system total real ruby 14.391000 0.000000 14.391000 ( 14.413000) yarv 7.094000 0.000000 7.094000 ( 7.105000) ----------------------------------------------------------- so_concatenate: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # based on code from Aristarkh A Zagorodnikov and Dat Nguyen STUFF = "hello\n" hello = '' 400000.times do |e| hello << STUFF end # puts hello.length -- user system total real ruby 0.438000 0.000000 0.438000 ( 0.440000) yarv 0.172000 0.016000 0.188000 ( 0.204000) ----------------------------------------------------------- so_count_words: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: wc-ruby.code,v 1.4 2004/11/13 07:43:32 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Paul Brannan require 'stringio' input = StringIO.new data = File.read($DRIVER_PATH + '/wc.input') 5000.times{|i| input.write data } input.seek 0 nl = nw = nc = 0 while true data = (input.read(4096) or break) << (input.gets || "") nc += data.length nl += data.count("\n") ((data.strip! || data).tr!("\n", " ") || data).squeeze! nw += data.count(" ") + 1 end # puts "#{nl} #{nw} #{nc}" -- user system total real ruby 1.063000 0.188000 1.251000 ( 1.308000) yarv 1.094000 0.187000 1.281000 ( 1.291000) ----------------------------------------------------------- so_exception: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ $HI = 0 $LO = 0 NUM = 250000 # Integer(ARGV[0] || 1) class Lo_Exception < Exception def initialize(num) @value = num end end class Hi_Exception < Exception def initialize(num) @value = num end end def some_function(num) begin hi_function(num) rescue print "We shouldn't get here, exception is: #{$!.type}\n" end end def hi_function(num) begin lo_function(num) rescue Hi_Exception $HI = $HI + 1 end end def lo_function(num) begin blowup(num) rescue Lo_Exception $LO = $LO + 1 end end def blowup(num) if num % 2 == 0 raise Lo_Exception.new(num) else raise Hi_Exception.new(num) end end i = 1 max = NUM+1 while i < max i+=1 some_function(i+1) end -- user system total real ruby 13.344000 0.000000 13.344000 ( 13.363000) yarv 4.813000 0.032000 4.845000 ( 4.833000) ----------------------------------------------------------- so_matrix: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ n = 600 #Integer(ARGV.shift || 1) size = 30 def mkmatrix(rows, cols) count = 1 mx = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| row[j] = count count += 1 end mx[bi] = row end mx end def mmult(rows, cols, m1, m2) m3 = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| val = 0 (0 .. (cols - 1)).each do |k| val += m1.at(bi).at(k) * m2.at(k).at(j) end row[j] = val end m3[bi] = row end m3 end m1 = mkmatrix(size, size) m2 = mkmatrix(size, size) mm = Array.new n.times do mm = mmult(size, size, m1, m2) end # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}" -- user system total real ruby 43.359000 0.000000 43.359000 ( 43.902000) yarv 19.235000 0.032000 19.267000 ( 19.302000) ----------------------------------------------------------- so_nested_loop: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # from Avi Bryant n = 16 # Integer(ARGV.shift || 1) x = 0 n.times do n.times do n.times do n.times do n.times do n.times do x += 1 end end end end end end # puts x -- user system total real ruby 11.375000 0.000000 11.375000 ( 11.421000) yarv 3.812000 0.000000 3.812000 ( 3.807000) ----------------------------------------------------------- so_random: # from http://www.bagley.org/~doug/shootout/bench/random/random.ruby IM = 139968 IA = 3877 IC = 29573 $last = 42.0 def gen_random(max) (max * ($last = ($last * IA + IC) % IM)) / IM end N = 1000000 i=0 while i