From a3e1b1ce7ed7e7ffac23015fc2fde56511b30681 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 31 Dec 2006 15:02:22 +0000 Subject: * Merge YARV git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- benchmark/bm_app_answer.rb | 15 ++ benchmark/bm_app_factorial.rb | 11 ++ benchmark/bm_app_fib.rb | 10 ++ benchmark/bm_app_mandelbrot.rb | 23 +++ benchmark/bm_app_pentomino.rb | 259 +++++++++++++++++++++++++++++++++ benchmark/bm_app_raise.rb | 8 + benchmark/bm_app_strconcat.rb | 5 + benchmark/bm_app_tak.rb | 13 ++ benchmark/bm_app_tarai.rb | 10 ++ benchmark/bm_loop_times.rb | 1 + benchmark/bm_loop_whileloop.rb | 4 + benchmark/bm_loop_whileloop2.rb | 5 + benchmark/bm_so_ackermann.rb | 19 +++ benchmark/bm_so_array.rb | 23 +++ benchmark/bm_so_concatenate.rb | 18 +++ benchmark/bm_so_count_words.rb | 18 +++ benchmark/bm_so_exception.rb | 61 ++++++++ benchmark/bm_so_lists.rb | 47 ++++++ benchmark/bm_so_matrix.rb | 48 ++++++ benchmark/bm_so_nested_loop.rb | 24 +++ benchmark/bm_so_object.rb | 56 +++++++ benchmark/bm_so_random.rb | 20 +++ benchmark/bm_so_sieve.rb | 24 +++ benchmark/bm_vm1_block.rb | 10 ++ benchmark/bm_vm1_const.rb | 8 + benchmark/bm_vm1_ensure.rb | 11 ++ benchmark/bm_vm1_length.rb | 9 ++ benchmark/bm_vm1_rescue.rb | 7 + benchmark/bm_vm1_simplereturn.rb | 9 ++ benchmark/bm_vm1_swap.rb | 8 + benchmark/bm_vm2_array.rb | 5 + benchmark/bm_vm2_method.rb | 9 ++ benchmark/bm_vm2_poly_method.rb | 20 +++ benchmark/bm_vm2_poly_method_ov.rb | 20 +++ benchmark/bm_vm2_proc.rb | 14 ++ benchmark/bm_vm2_regexp.rb | 6 + benchmark/bm_vm2_send.rb | 12 ++ benchmark/bm_vm2_super.rb | 20 +++ benchmark/bm_vm2_unif1.rb | 8 + benchmark/bm_vm2_zsuper.rb | 20 +++ benchmark/bm_vm3_thread_create_join.rb | 6 + benchmark/bmx_temp.rb | 57 ++++++++ benchmark/other-lang/ack.pl | 11 ++ benchmark/other-lang/ack.py | 16 ++ benchmark/other-lang/ack.rb | 12 ++ benchmark/other-lang/ack.scm | 7 + benchmark/other-lang/eval.rb | 66 +++++++++ benchmark/other-lang/fact.pl | 13 ++ benchmark/other-lang/fact.py | 18 +++ benchmark/other-lang/fact.rb | 13 ++ benchmark/other-lang/fact.scm | 8 + benchmark/other-lang/fib.pl | 11 ++ benchmark/other-lang/fib.py | 7 + benchmark/other-lang/fib.rb | 9 ++ benchmark/other-lang/fib.scm | 7 + benchmark/other-lang/loop.pl | 3 + benchmark/other-lang/loop.py | 2 + benchmark/other-lang/loop.rb | 4 + benchmark/other-lang/loop.scm | 1 + benchmark/other-lang/loop2.rb | 1 + benchmark/other-lang/tak.pl | 11 ++ benchmark/other-lang/tak.py | 8 + benchmark/other-lang/tak.rb | 13 ++ benchmark/other-lang/tak.scm | 10 ++ benchmark/report.rb | 81 +++++++++++ benchmark/run.rb | 137 +++++++++++++++++ benchmark/run_rite.rb | 129 ++++++++++++++++ benchmark/runc.rb | 29 ++++ benchmark/wc.input.base | 25 ++++ 69 files changed, 1633 insertions(+) create mode 100644 benchmark/bm_app_answer.rb create mode 100644 benchmark/bm_app_factorial.rb create mode 100644 benchmark/bm_app_fib.rb create mode 100644 benchmark/bm_app_mandelbrot.rb create mode 100644 benchmark/bm_app_pentomino.rb create mode 100644 benchmark/bm_app_raise.rb create mode 100644 benchmark/bm_app_strconcat.rb create mode 100644 benchmark/bm_app_tak.rb create mode 100644 benchmark/bm_app_tarai.rb create mode 100644 benchmark/bm_loop_times.rb create mode 100644 benchmark/bm_loop_whileloop.rb create mode 100644 benchmark/bm_loop_whileloop2.rb create mode 100644 benchmark/bm_so_ackermann.rb create mode 100644 benchmark/bm_so_array.rb create mode 100644 benchmark/bm_so_concatenate.rb create mode 100644 benchmark/bm_so_count_words.rb create mode 100644 benchmark/bm_so_exception.rb create mode 100644 benchmark/bm_so_lists.rb create mode 100644 benchmark/bm_so_matrix.rb create mode 100644 benchmark/bm_so_nested_loop.rb create mode 100644 benchmark/bm_so_object.rb create mode 100644 benchmark/bm_so_random.rb create mode 100644 benchmark/bm_so_sieve.rb create mode 100644 benchmark/bm_vm1_block.rb create mode 100644 benchmark/bm_vm1_const.rb create mode 100644 benchmark/bm_vm1_ensure.rb create mode 100644 benchmark/bm_vm1_length.rb create mode 100644 benchmark/bm_vm1_rescue.rb create mode 100644 benchmark/bm_vm1_simplereturn.rb create mode 100644 benchmark/bm_vm1_swap.rb create mode 100644 benchmark/bm_vm2_array.rb create mode 100644 benchmark/bm_vm2_method.rb create mode 100644 benchmark/bm_vm2_poly_method.rb create mode 100644 benchmark/bm_vm2_poly_method_ov.rb create mode 100644 benchmark/bm_vm2_proc.rb create mode 100644 benchmark/bm_vm2_regexp.rb create mode 100644 benchmark/bm_vm2_send.rb create mode 100644 benchmark/bm_vm2_super.rb create mode 100644 benchmark/bm_vm2_unif1.rb create mode 100644 benchmark/bm_vm2_zsuper.rb create mode 100644 benchmark/bm_vm3_thread_create_join.rb create mode 100644 benchmark/bmx_temp.rb create mode 100644 benchmark/other-lang/ack.pl create mode 100644 benchmark/other-lang/ack.py create mode 100644 benchmark/other-lang/ack.rb create mode 100644 benchmark/other-lang/ack.scm create mode 100644 benchmark/other-lang/eval.rb create mode 100644 benchmark/other-lang/fact.pl create mode 100644 benchmark/other-lang/fact.py create mode 100644 benchmark/other-lang/fact.rb create mode 100644 benchmark/other-lang/fact.scm create mode 100644 benchmark/other-lang/fib.pl create mode 100644 benchmark/other-lang/fib.py create mode 100644 benchmark/other-lang/fib.rb create mode 100644 benchmark/other-lang/fib.scm create mode 100644 benchmark/other-lang/loop.pl create mode 100644 benchmark/other-lang/loop.py create mode 100644 benchmark/other-lang/loop.rb create mode 100644 benchmark/other-lang/loop.scm create mode 100644 benchmark/other-lang/loop2.rb create mode 100644 benchmark/other-lang/tak.pl create mode 100644 benchmark/other-lang/tak.py create mode 100644 benchmark/other-lang/tak.rb create mode 100644 benchmark/other-lang/tak.scm create mode 100644 benchmark/report.rb create mode 100644 benchmark/run.rb create mode 100644 benchmark/run_rite.rb create mode 100644 benchmark/runc.rb create mode 100644 benchmark/wc.input.base (limited to 'benchmark') diff --git a/benchmark/bm_app_answer.rb b/benchmark/bm_app_answer.rb new file mode 100644 index 0000000000..00f830e1dc --- /dev/null +++ b/benchmark/bm_app_answer.rb @@ -0,0 +1,15 @@ +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 + +def the_answer_to_life_the_universe_and_everything + (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i +end + +answer = the_answer_to_life_the_universe_and_everything diff --git a/benchmark/bm_app_factorial.rb b/benchmark/bm_app_factorial.rb new file mode 100644 index 0000000000..cfafd626a8 --- /dev/null +++ b/benchmark/bm_app_factorial.rb @@ -0,0 +1,11 @@ +def fact(n) + if(n > 1) + n * fact(n-1) + else + 1 + end +end + +8.times{ + fact(5000) +} \ No newline at end of file diff --git a/benchmark/bm_app_fib.rb b/benchmark/bm_app_fib.rb new file mode 100644 index 0000000000..65a149e5c4 --- /dev/null +++ b/benchmark/bm_app_fib.rb @@ -0,0 +1,10 @@ +def fib n + if n < 3 + 1 + else + fib(n-1) + fib(n-2) + end +end + +fib(34) + diff --git a/benchmark/bm_app_mandelbrot.rb b/benchmark/bm_app_mandelbrot.rb new file mode 100644 index 0000000000..e981775ad3 --- /dev/null +++ b/benchmark/bm_app_mandelbrot.rb @@ -0,0 +1,23 @@ +require 'complex' + +def mandelbrot? z + i = 0 + while i<100 + i+=1 + z = z * z + return false if z.abs > 2 + end + true +end + +ary = [] + +(0..100).each{|dx| + (0..100).each{|dy| + x = dx / 50.0 + y = dy / 50.0 + c = Complex(x, y) + ary << c if mandelbrot?(c) + } +} + diff --git a/benchmark/bm_app_pentomino.rb b/benchmark/bm_app_pentomino.rb new file mode 100644 index 0000000000..0fc80fade9 --- /dev/null +++ b/benchmark/bm_app_pentomino.rb @@ -0,0 +1,259 @@ +#!/usr/local/bin/ruby +# This program is contributed by Shin Nishiyama + + +# modified by K.Sasada + +NP = 5 +ROW = 8 + NP +COL = 8 + +$p = [] +$b = [] +$no = 0 + +def piece(n, a, nb) + nb.each{|x| + a[n] = x + if n == NP-1 + $p << [a.sort] + else + nbc=nb.clone + [-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 + end + } + nbc.delete x + piece(n+1,a[0..n],nbc) + end + } +end + +def kikaku(a) + a.collect {|x| x - a[0]} +end +def ud(a) + kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) +end +def rl(a) + kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) +end +def xy(a) + kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) +end + +def mkpieces + piece(0,[],[0]) + $p.each do |a| + a0 = a[0] + a[1] = ud(a0) + a[2] = rl(a0) + a[3] = ud(rl(a0)) + a[4] = xy(a0) + a[5] = ud(xy(a0)) + a[6] = rl(xy(a0)) + a[7] = ud(rl(xy(a0))) + a.sort! + a.uniq! + end + $p.uniq!.sort! {|x,y| x[0] <=> y[0] } +end + +def mkboard + (0...ROW*COL).each{|i| + if i % ROW >= ROW-NP + $b[i] = -2 + else + $b[i] = -1 + end + $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 + } +end + +def pboard + return # skip print + print "No. #$no\n" + (0...COL).each{|i| + print "|" + (0...ROW-NP).each{|j| + x = $b[i*ROW+j] + if x < 0 + print "..|" + else + printf "%2d|",x+1 + end + } + print "\n" + } + print "\n" +end + +$pnum=[] +def setpiece(a,pos) + if a.length == $p.length then + $no += 1 + pboard + return + end + while $b[pos] != -1 + pos += 1 + end + ($pnum - a).each do |i| + $p[i].each do |x| + f = 0 + x.each{|s| + if $b[pos+s] != -1 + f=1 + break + end + } + if f == 0 then + x.each{|s| + $b[pos+s] = i + } + a << i + setpiece(a.clone, pos) + a.pop + x.each{|s| + $b[pos+s] = -1 + } + end + end + end +end + +mkpieces +mkboard +$p[4] = [$p[4][0]] +$pnum = (0...$p.length).to_a +setpiece([],0) + + +__END__ + +# original + +NP = 5 +ROW = 8 + NP +COL = 8 + +$p = [] +$b = [] +$no = 0 + +def piece(n,a,nb) + for x in nb + a[n] = x + if n == NP-1 + $p << [a.sort] + else + nbc=nb.clone + 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 + end + end + nbc.delete x + piece(n+1,a[0..n],nbc) + end + end +end + +def kikaku(a) + a.collect {|x| x - a[0]} +end +def ud(a) + kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) +end +def rl(a) + kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) +end +def xy(a) + kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) +end + +def mkpieces + piece(0,[],[0]) + $p.each do |a| + a0 = a[0] + a[1] = ud(a0) + a[2] = rl(a0) + a[3] = ud(rl(a0)) + a[4] = xy(a0) + a[5] = ud(xy(a0)) + a[6] = rl(xy(a0)) + a[7] = ud(rl(xy(a0))) + a.sort! + a.uniq! + end + $p.uniq!.sort! {|x,y| x[0] <=> y[0] } +end + +def mkboard + for i in 0...ROW*COL + if i % ROW >= ROW-NP + $b[i] = -2 + else + $b[i] = -1 + end + $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 + end +end + +def pboard + print "No. #$no\n" + for i in 0...COL + print "|" + for j in 0...ROW-NP + x = $b[i*ROW+j] + if x < 0 + print "..|" + else + printf "%2d|",x+1 + end + end + print "\n" + end + print "\n" +end + +$pnum=[] +def setpiece(a,pos) + if a.length == $p.length then + $no += 1 + pboard + return + end + while $b[pos] != -1 + pos += 1 + end + ($pnum - a).each do |i| + $p[i].each do |x| + f = 0 + for s in x do + if $b[pos+s] != -1 + f=1 + break + end + end + if f == 0 then + for s in x do + $b[pos+s] = i + end + a << i + setpiece(a.clone, pos) + a.pop + for s in x do + $b[pos+s] = -1 + end + end + end + end +end + +mkpieces +mkboard +$p[4] = [$p[4][0]] +$pnum = (0...$p.length).to_a +setpiece([],0) diff --git a/benchmark/bm_app_raise.rb b/benchmark/bm_app_raise.rb new file mode 100644 index 0000000000..0e3297e62e --- /dev/null +++ b/benchmark/bm_app_raise.rb @@ -0,0 +1,8 @@ +i=0 +while i<300000 + i+=1 + begin + raise + rescue + end +end diff --git a/benchmark/bm_app_strconcat.rb b/benchmark/bm_app_strconcat.rb new file mode 100644 index 0000000000..cc0e929da1 --- /dev/null +++ b/benchmark/bm_app_strconcat.rb @@ -0,0 +1,5 @@ +i=0 +while i<500000 + "#{1+1} #{1+1} #{1+1}" + i+=1 +end diff --git a/benchmark/bm_app_tak.rb b/benchmark/bm_app_tak.rb new file mode 100644 index 0000000000..d70d5db8f8 --- /dev/null +++ b/benchmark/bm_app_tak.rb @@ -0,0 +1,13 @@ + +def tak x, y, z + unless y < x + z + else + tak( tak(x-1, y, z), + tak(y-1, z, x), + tak(z-1, x, y)) + end +end + +tak(18, 9, 0) + diff --git a/benchmark/bm_app_tarai.rb b/benchmark/bm_app_tarai.rb new file mode 100644 index 0000000000..851f36d990 --- /dev/null +++ b/benchmark/bm_app_tarai.rb @@ -0,0 +1,10 @@ +def tarai( x, y, z ) + if x <= y + then y + else tarai(tarai(x-1, y, z), + tarai(y-1, z, x), + tarai(z-1, x, y)) + end +end + +tarai(12, 6, 0) diff --git a/benchmark/bm_loop_times.rb b/benchmark/bm_loop_times.rb new file mode 100644 index 0000000000..6bda28d8f6 --- /dev/null +++ b/benchmark/bm_loop_times.rb @@ -0,0 +1 @@ +30000000.times{|e|} diff --git a/benchmark/bm_loop_whileloop.rb b/benchmark/bm_loop_whileloop.rb new file mode 100644 index 0000000000..59b89cc519 --- /dev/null +++ b/benchmark/bm_loop_whileloop.rb @@ -0,0 +1,4 @@ +i = 0 +while i<30000000 # benchmark loop 1 + i+=1 +end diff --git a/benchmark/bm_loop_whileloop2.rb b/benchmark/bm_loop_whileloop2.rb new file mode 100644 index 0000000000..976d4a9bad --- /dev/null +++ b/benchmark/bm_loop_whileloop2.rb @@ -0,0 +1,5 @@ +i=0 +while i<6000000 # benchmark loop 2 + i+=1 +end + diff --git a/benchmark/bm_so_ackermann.rb b/benchmark/bm_so_ackermann.rb new file mode 100644 index 0000000000..fce9585825 --- /dev/null +++ b/benchmark/bm_so_ackermann.rb @@ -0,0 +1,19 @@ +#!/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 = 9 +ack(3, NUM) + + diff --git a/benchmark/bm_so_array.rb b/benchmark/bm_so_array.rb new file mode 100644 index 0000000000..a82a37cf16 --- /dev/null +++ b/benchmark/bm_so_array.rb @@ -0,0 +1,23 @@ +#!/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}" + + diff --git a/benchmark/bm_so_concatenate.rb b/benchmark/bm_so_concatenate.rb new file mode 100644 index 0000000000..153efea1db --- /dev/null +++ b/benchmark/bm_so_concatenate.rb @@ -0,0 +1,18 @@ +#!/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" +i=0 +while i<10 + i+=1 + hello = '' + 400000.times do |e| + hello << STUFF + end +end +# puts hello.length + + diff --git a/benchmark/bm_so_count_words.rb b/benchmark/bm_so_count_words.rb new file mode 100644 index 0000000000..a24062d258 --- /dev/null +++ b/benchmark/bm_so_count_words.rb @@ -0,0 +1,18 @@ +#!/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 + +input = open(File.join(File.dirname($0), 'wc.input'), 'rb') + +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 +# STDERR.puts "#{nl} #{nw} #{nc}" + diff --git a/benchmark/bm_so_exception.rb b/benchmark/bm_so_exception.rb new file mode 100644 index 0000000000..d829474750 --- /dev/null +++ b/benchmark/bm_so_exception.rb @@ -0,0 +1,61 @@ +#!/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 diff --git a/benchmark/bm_so_lists.rb b/benchmark/bm_so_lists.rb new file mode 100644 index 0000000000..1fcf24bbc6 --- /dev/null +++ b/benchmark/bm_so_lists.rb @@ -0,0 +1,47 @@ +#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 = (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= @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 + diff --git a/benchmark/bm_so_random.rb b/benchmark/bm_so_random.rb new file mode 100644 index 0000000000..8bc30841a8 --- /dev/null +++ b/benchmark/bm_so_random.rb @@ -0,0 +1,20 @@ +# from http://www.bagley.org/~doug/shootout/bench/random/random.ruby + +IM = 139968.0 +IA = 3877.0 +IC = 29573.0 + +$last = 42.0 + +def gen_random(max) + (max * ($last = ($last * IA + IC) % IM)) / IM +end + +N = 1000000 + +i=0 +while i exec_command_error_variable + puts "\t" + exec_command_error_variable.message + end + EOP +end + +def benchmark cmd + rubybin = ENV['RUBY'] || File.join( + Config::CONFIG["bindir"], + Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"]) + + IO.popen(rubybin, 'r+'){|io| + io.write cmd + io.close_write + return io.gets + } +end + +def ruby_exec file + prog = exec_command 'ruby', file, 'load' + benchmark prog +end + +def yarv_exec file + prog = exec_command 'yarv', file, 'YARVUtil.load_bm' + benchmark prog +end + +$wr = $wy = nil + +def measure bench + file = File.dirname($0) + "/bm_#{bench}.rb" + r = ruby_exec(file).to_f + y = yarv_exec(file).to_f + puts "#{bench}\t#{r}\t#{y}" +end + +def measure2 + r = ruby_exec.to_f + y = yarv_exec.to_f + puts r/y +end + +if $0 == __FILE__ + %w{ + whileloop + whileloop2 + times + const + method + poly_method + block + rescue + rescue2 + }.each{|bench| + measure bench + } +end + + + + diff --git a/benchmark/run.rb b/benchmark/run.rb new file mode 100644 index 0000000000..b84d093828 --- /dev/null +++ b/benchmark/run.rb @@ -0,0 +1,137 @@ +# +# YARV benchmark driver +# + +require 'yarvutil' +require 'benchmark' +require 'rbconfig' + +$yarvonly = false +$rubyonly = false + +$results = [] + +puts "ruby #{RUBY_VERSION} #{RUBY_PLATFORM}(#{RUBY_RELEASE_DATE})" +puts YARVCore::VERSION + " rev: #{YARVCore::REV} (#{YARVCore::DATE})" +puts YARVCore::OPTS +puts + +def bm file + prog = File.read(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 < e + puts + puts "** benchmark failure: #{e}" + puts e.backtrace + 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 +end + +def ruby_exec file + prog = exec_command 'ruby', file, 'load' + benchmark prog +end + +def yarv_exec file + prog = exec_command 'yarv', file, 'YARVUtil.load_bm' + benchmark prog +end + +if $0 == __FILE__ + ARGV.each{|arg| + if /\A(--yarv)|(-y)/ =~ arg + $yarvonly = true + elsif /\A(--ruby)|(-r)/ =~ arg + $rubyonly = true + end + } + ARGV.delete_if{|arg| + /\A-/ =~ arg + } + + 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 + + diff --git a/benchmark/run_rite.rb b/benchmark/run_rite.rb new file mode 100644 index 0000000000..3b437c82ab --- /dev/null +++ b/benchmark/run_rite.rb @@ -0,0 +1,129 @@ +# +# 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.read(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 < 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 + diff --git a/benchmark/runc.rb b/benchmark/runc.rb new file mode 100644 index 0000000000..20e06b2355 --- /dev/null +++ b/benchmark/runc.rb @@ -0,0 +1,29 @@ +# +# +# + +require 'benchmark' +require 'rbconfig' + +$rubybin = ENV['RUBY'] || File.join( + Config::CONFIG["bindir"], + Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"]) + +def runfile file + puts file + file = File.join(File.dirname($0), 'contrib', file) + Benchmark.bm{|x| + x.report('ruby'){ + system("#{$rubybin} #{file}") + } + x.report('yarv'){ + system("#{$rubybin} -rite -I.. #{file}") + } + } +end + +ARGV.each{|file| + runfile file +} + + diff --git a/benchmark/wc.input.base b/benchmark/wc.input.base new file mode 100644 index 0000000000..88b5c69c96 --- /dev/null +++ b/benchmark/wc.input.base @@ -0,0 +1,25 @@ +Subject: Re: Who was Izchak Miller? +From: "Jane D. Anonymous" +Date: 1996/04/28 +Message-Id: <4lv7bc$oh@news.ycc.yale.edu> +References: <317C405E.5DFA@panix.com> <4lk6vl$gde@ns.oar.net> +To: 75176.2330@compuserve.com +Content-Type: text/plain; charset=us-ascii +Organization: Yale University +X-Url: news:4lk6vl$gde@ns.oar.net +Mime-Version: 1.0 +Newsgroups: rec.games.roguelike.nethack +X-Mailer: Mozilla 1.1N (Macintosh; I; 68K) + +Hello there, Izchak Miller was my father. When I was younger I spent +many a night, hunched over the keyboard with a cup of tea, playing +nethack with him and my brother. my dad was a philosopher with a strong +weakness for fantasy/sci fi. I remember when he started to get involved +with the Nethack team- my brother's Dungeons and Dragons monster book +found a regular place beside my dad's desk. it's nice to see him living +on in the game he loved so much :-). + Tamar Miller + +The following is a really long word of 5000 characters: + +wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww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