pbk-15:~/devl/yarv-0.2.0 $ make benchmark /usr/local/bin/ruby -I. -I. ./rb/aotcompile.rb -I. -I/usr/local/lib/ruby/1.9/powerpc-darwin7.7.0 -I/usr/local/lib/ruby/1.9/powerpc-darwin7.7.0 -I. -DDISPATCH_THREADED_CODE -DDISPATCH_DIRECT_THREADED_CODE -DOPT_BASIC_OPERATIONS -DOPT_REGEXP_MATCH -DOPT_INSNS_UNIFICATION -DOPT_STACK_CACHING -DINLINE_METHOD_CACHE --srcdir=. gcc -fno-common -g -O2 -pipe -fno-common -I. -I/usr/local/lib/ruby/1.9/powerpc-darwin7.7.0 -I/usr/local/lib/ruby/1.9/powerpc-darwin7.7.0 -I. -DDISPATCH_THREADED_CODE -DDISPATCH_DIRECT_THREADED_CODE -DOPT_BASIC_OPERATIONS -DOPT_REGEXP_MATCH -DOPT_INSNS_UNIFICATION -DOPT_STACK_CACHING -DINLINE_METHOD_CACHE -c compiled.c cc -dynamic -bundle -undefined suppress -flat_namespace -L"/usr/local/lib" -o yarvcore.bundle compile.o compiled.o debug.o disasm.o jitcompile.o vm.o yarvcore.o yarvsubst.o -ldl -lobjc /usr/local/bin/ruby -I. ./benchmark/run.rb ruby 1.9.0 powerpc-darwin7.7.0(2005-01-12) YARVCore 0.2.0 rev: 154 (2005-03-04) [direct threaded code] [optimize basic operation] [optimize regexp match] [stack caching] [inline method cache] ----------------------------------------------------------- array: i=0 while i<10000000 i+=1 a = [1,2,3,4,5,6,7,8,9,10] end -- user system total real ruby 42.390000 0.100000 42.490000 ( 44.780388) yarv 13.190000 0.110000 13.300000 ( 13.973322) ----------------------------------------------------------- block: def m yield end i=0 while i<1000000 i+=1 m{ } end -- user system total real ruby 3.050000 0.000000 3.050000 ( 3.092854) yarv 0.390000 0.000000 0.390000 ( 0.395801) ----------------------------------------------------------- const: Const = 1 i = 0 while i < 10000000 i+= 1 j = Const k = Const end -- user system total real ruby 21.900000 0.010000 21.910000 ( 22.295421) yarv 1.680000 0.000000 1.680000 ( 1.707209) ----------------------------------------------------------- ensure: i=0 while i<1000000 i+=1 begin begin ensure end ensure end end -- user system total real ruby 1.580000 0.000000 1.580000 ( 1.627552) yarv 0.110000 0.000000 0.110000 ( 0.109697) ----------------------------------------------------------- factorial: def fact(n) if(n > 1) n * fact(n-1) else 1 end end fact(7300) -- user system total real ruby stack level too deep yarv 0.250000 0.020000 0.270000 ( 0.266155) ----------------------------------------------------------- fib: def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(32) -- user system total real ruby 10.640000 0.020000 10.660000 ( 10.867425) yarv 1.150000 0.000000 1.150000 ( 1.165137) ----------------------------------------------------------- lists: #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby NUM = 10 SIZE = 10000 def test_lists() # create a list of integers (Li1) from 1 to SIZE li1 = (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 stack level too deep yarv 0.010000 0.000000 0.010000 ( 0.004736) ----------------------------------------------------------- regexp: i=0 while i<1000000 /hoge/ =~ 'xxxhogexxx' i+=1 end -- user system total real ruby 2.800000 0.000000 2.800000 ( 2.929835) yarv 1.180000 0.000000 1.180000 ( 1.233916) ----------------------------------------------------------- rescue: i=0 while i<10000000 i+=1 begin rescue end end -- user system total real ruby 18.650000 0.020000 18.670000 ( 19.129190) yarv 1.330000 0.000000 1.330000 ( 1.359620) ----------------------------------------------------------- rescue2: i=0 while i<100000 i+=1 begin raise rescue end end -- user system total real ruby 2.260000 0.210000 2.470000 ( 2.587030) yarv 1.670000 0.210000 1.880000 ( 1.970383) ----------------------------------------------------------- simpleiter: 1000000.times{|simpleiter| simpleiter } -- user system total real ruby 0.900000 0.000000 0.900000 ( 0.942726) yarv 0.400000 0.000000 0.400000 ( 0.429443) ----------------------------------------------------------- simplereturn: def m return 1 end i=0 while i<1000000 i+=1 m end -- user system total real ruby 2.280000 0.000000 2.280000 ( 2.306492) yarv 0.280000 0.000000 0.280000 ( 0.277903) ----------------------------------------------------------- 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 stack level too deep yarv 0.310000 0.000000 0.310000 ( 0.310373) ----------------------------------------------------------- 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 26.630000 0.050000 26.680000 ( 27.155358) yarv 10.760000 0.000000 10.760000 ( 10.933831) ----------------------------------------------------------- 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.710000 0.010000 0.720000 ( 0.738011) yarv 0.270000 0.000000 0.270000 ( 0.294169) ----------------------------------------------------------- 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 0.600000 0.190000 0.790000 ( 0.919376) yarv 0.640000 0.150000 0.790000 ( 0.810519) ----------------------------------------------------------- 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 10.800000 0.710000 11.510000 ( 12.101493) yarv 7.520000 0.510000 8.030000 ( 9.606575) ----------------------------------------------------------- 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 = 60 #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 7.930000 0.060000 7.990000 ( 9.536280) yarv 2.470000 0.030000 2.500000 ( 2.811987) ----------------------------------------------------------- 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 23.880000 0.040000 23.920000 ( 26.016732) yarv 8.530000 0.080000 8.610000 ( 10.677813) ----------------------------------------------------------- so_object: #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Aristarkh Zagorodnikov class Toggle def initialize(start_state) @bool = start_state end def value @bool end def activate @bool = !@bool self end end class NthToggle < Toggle def initialize(start_state, max_counter) super start_state @count_max = max_counter @counter = 0 end def activate @counter += 1 if @counter >= @count_max @bool = !@bool @counter = 0 end self end end n = 1500000 # (ARGV.shift || 1).to_i toggle = Toggle.new 1 5.times do toggle.activate.value ? 'true' : 'false' end n.times do toggle = Toggle.new 1 end ntoggle = NthToggle.new 1, 3 8.times do ntoggle.activate.value ? 'true' : 'false' end n.times do ntoggle = NthToggle.new 1, 3 end -- user system total real ruby 20.150000 0.110000 20.260000 ( 26.968556) yarv 16.990000 0.050000 17.040000 ( 19.287725) ----------------------------------------------------------- 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