git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shyouhei 2007-02-12 23:01:19 +00:00
Родитель 1a4b93cf92
Коммит fd81221a8e
81 изменённых файлов: 13317 добавлений и 13317 удалений

Просмотреть файл

@ -1,15 +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
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

Просмотреть файл

@ -1,11 +1,11 @@
def fact(n)
if(n > 1)
n * fact(n-1)
else
1
end
end
8.times{
fact(5000)
def fact(n)
if(n > 1)
n * fact(n-1)
else
1
end
end
8.times{
fact(5000)
}

Просмотреть файл

@ -1,10 +1,10 @@
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)

Просмотреть файл

@ -1,23 +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)
}
}
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)
}
}

Просмотреть файл

@ -1,259 +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.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
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.dup, 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.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
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.dup, 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)
#!/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.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
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.dup, 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.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
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.dup, 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)

Просмотреть файл

@ -1,8 +1,8 @@
i=0
while i<300000
i+=1
begin
raise
rescue
end
end
i=0
while i<300000
i+=1
begin
raise
rescue
end
end

Просмотреть файл

@ -1,5 +1,5 @@
i=0
while i<500000
"#{1+1} #{1+1} #{1+1}"
i+=1
end
i=0
while i<500000
"#{1+1} #{1+1} #{1+1}"
i+=1
end

Просмотреть файл

@ -1,13 +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)
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)

Просмотреть файл

@ -1,10 +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)
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)

Просмотреть файл

@ -1 +1 @@
30000000.times{|e|}
30000000.times{|e|}

Просмотреть файл

@ -1,4 +1,4 @@
i = 0
while i<30000000 # benchmark loop 1
i+=1
end
i = 0
while i<30000000 # benchmark loop 1
i+=1
end

Просмотреть файл

@ -1,5 +1,5 @@
i=0
while i<6000000 # benchmark loop 2
i+=1
end
i=0
while i<6000000 # benchmark loop 2
i+=1
end

Просмотреть файл

@ -1,19 +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)
#!/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)

Просмотреть файл

@ -1,23 +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}"
#!/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}"

Просмотреть файл

@ -1,18 +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
#!/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

Просмотреть файл

@ -1,18 +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}"
#!/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}"

Просмотреть файл

@ -1,61 +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
#!/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

Просмотреть файл

@ -1,47 +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<NUM
i+=1
result = test_lists()
end
result
#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<NUM
i+=1
result = test_lists()
end
result

Просмотреть файл

@ -1,48 +1,48 @@
#!/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]}"
#!/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]}"

Просмотреть файл

@ -1,24 +1,24 @@
#!/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
#!/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

Просмотреть файл

@ -1,56 +1,56 @@
#!/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
#!/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

Просмотреть файл

@ -1,20 +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<N
i+=1
gen_random(100.0)
end
# "%.9f" % gen_random(100.0)
# 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<N
i+=1
gen_random(100.0)
end
# "%.9f" % gen_random(100.0)

Просмотреть файл

@ -1,24 +1,24 @@
# from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
num = 40
count = i = j = 0
flags0 = Array.new(8192,1)
k = 0
while k < num
k+=1
count = 0
flags = flags0.dup
i = 2
while i<8192
i+=1
if flags[i]
# remove all multiples of prime: i
j = i*i
while j < 8192
j += i
flags[j] = nil
end
count += 1
end
end
end
count
# from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
num = 40
count = i = j = 0
flags0 = Array.new(8192,1)
k = 0
while k < num
k+=1
count = 0
flags = flags0.dup
i = 2
while i<8192
i+=1
if flags[i]
# remove all multiples of prime: i
j = i*i
while j < 8192
j += i
flags[j] = nil
end
count += 1
end
end
end
count

Просмотреть файл

@ -1,10 +1,10 @@
def m
yield
end
i=0
while i<30000000 # while loop 1
i+=1
m{
}
def m
yield
end
i=0
while i<30000000 # while loop 1
i+=1
m{
}
end

Просмотреть файл

@ -1,8 +1,8 @@
Const = 1
i = 0
while i<30000000 # while loop 1
i+= 1
j = Const
k = Const
end
Const = 1
i = 0
while i<30000000 # while loop 1
i+= 1
j = Const
k = Const
end

Просмотреть файл

@ -1,11 +1,11 @@
i=0
while i<30000000 # benchmark loop 1
i+=1
begin
begin
ensure
end
ensure
end
end
i=0
while i<30000000 # benchmark loop 1
i+=1
begin
begin
ensure
end
ensure
end
end

Просмотреть файл

@ -1,9 +1,9 @@
a = 'abc'
b = [1, 2, 3]
i=0
while i<30000000 # while loop 1
i+=1
a.length
b.length
end
a = 'abc'
b = [1, 2, 3]
i=0
while i<30000000 # while loop 1
i+=1
a.length
b.length
end

Просмотреть файл

@ -1,7 +1,7 @@
i=0
while i<30000000 # while loop 1
i+=1
begin
rescue
end
end
i=0
while i<30000000 # while loop 1
i+=1
begin
rescue
end
end

Просмотреть файл

@ -1,9 +1,9 @@
def m
return 1
end
i=0
while i<30000000 # while loop 1
i+=1
m
end
def m
return 1
end
i=0
while i<30000000 # while loop 1
i+=1
m
end

Просмотреть файл

@ -1,8 +1,8 @@
a = 1
b = 2
i=0
while i<30000000 # while loop 1
i+=1
a, b = b, a
end
a = 1
b = 2
i=0
while i<30000000 # while loop 1
i+=1
a, b = b, a
end

Просмотреть файл

@ -1,5 +1,5 @@
i=0
while i<6000000 # benchmark loop 2
i+=1
a = [1,2,3,4,5,6,7,8,9,10]
end
i=0
while i<6000000 # benchmark loop 2
i+=1
a = [1,2,3,4,5,6,7,8,9,10]
end

Просмотреть файл

@ -1,9 +1,9 @@
def m
nil
end
i=0
while i<6000000 # benchmark loop 2
i+=1
m; m; m; m; m; m; m; m;
end
def m
nil
end
i=0
while i<6000000 # benchmark loop 2
i+=1
m; m; m; m; m; m; m; m;
end

Просмотреть файл

@ -1,20 +1,20 @@
class C1
def m
1
end
end
class C2
def m
2
end
end
o1 = C1.new
o2 = C2.new
i=0
while i<6000000 # benchmark loop 2
o = (i % 2 == 0) ? o1 : o2
o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m
i+=1
end
class C1
def m
1
end
end
class C2
def m
2
end
end
o1 = C1.new
o2 = C2.new
i=0
while i<6000000 # benchmark loop 2
o = (i % 2 == 0) ? o1 : o2
o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m
i+=1
end

Просмотреть файл

@ -1,20 +1,20 @@
class C1
def m
1
end
end
class C2
def m
2
end
end
o1 = C1.new
o2 = C2.new
i=0
while i<6000000 # benchmark loop 2
o = (i % 2 == 0) ? o1 : o2
# o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m
i+=1
end
class C1
def m
1
end
end
class C2
def m
2
end
end
o1 = C1.new
o2 = C2.new
i=0
while i<6000000 # benchmark loop 2
o = (i % 2 == 0) ? o1 : o2
# o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m
i+=1
end

Просмотреть файл

@ -1,14 +1,14 @@
def m &b
b
end
pr = m{
a = 1
}
i=0
while i<6000000 # benchmark loop 2
i+=1
pr.call
end
def m &b
b
end
pr = m{
a = 1
}
i=0
while i<6000000 # benchmark loop 2
i+=1
pr.call
end

Просмотреть файл

@ -1,6 +1,6 @@
i=0
str = 'xxxhogexxx'
while i<6000000 # benchmark loop 2
/hoge/ =~ str
i+=1
end
i=0
str = 'xxxhogexxx'
while i<6000000 # benchmark loop 2
/hoge/ =~ str
i+=1
end

Просмотреть файл

@ -1,12 +1,12 @@
class C
def m
end
end
o = C.new
i=0
while i<6000000 # benchmark loop 2
i+=1
o.__send__ :m
end
class C
def m
end
end
o = C.new
i=0
while i<6000000 # benchmark loop 2
i+=1
o.__send__ :m
end

Просмотреть файл

@ -1,20 +1,20 @@
class C
def m
1
end
end
class CC < C
def m
super()
end
end
obj = CC.new
i = 0
while i<6000000 # benchmark loop 2
obj.m
i+=1
end
class C
def m
1
end
end
class CC < C
def m
super()
end
end
obj = CC.new
i = 0
while i<6000000 # benchmark loop 2
obj.m
i+=1
end

Просмотреть файл

@ -1,8 +1,8 @@
i = 0
def m a, b
end
while i<6000000 # benchmark loop 2
i+=1
m 100, 200
end
i = 0
def m a, b
end
while i<6000000 # benchmark loop 2
i+=1
m 100, 200
end

Просмотреть файл

@ -1,20 +1,20 @@
i = 0
class C
def m a
1
end
end
class CC < C
def m a
super
end
end
obj = CC.new
while i<6000000 # benchmark loop 2
obj.m 10
i+=1
end
i = 0
class C
def m a
1
end
end
class CC < C
def m a
super
end
end
obj = CC.new
while i<6000000 # benchmark loop 2
obj.m 10
i+=1
end

Просмотреть файл

@ -1,6 +1,6 @@
i=0
while i<1000 # benchmark loop 3
i+=1
Thread.new{
}.join
end
i=0
while i<1000 # benchmark loop 3
i+=1
Thread.new{
}.join
end

Просмотреть файл

@ -1,11 +1,11 @@
use integer;
sub Ack {
return $_[0] ? ($_[1] ? Ack($_[0]-1, Ack($_[0], $_[1]-1))
: Ack($_[0]-1, 1))
: $_[1]+1;
}
my $NUM = 9;
$NUM = 1 if ($NUM < 1);
my $ack = Ack(3, $NUM);
use integer;
sub Ack {
return $_[0] ? ($_[1] ? Ack($_[0]-1, Ack($_[0], $_[1]-1))
: Ack($_[0]-1, 1))
: $_[1]+1;
}
my $NUM = 9;
$NUM = 1 if ($NUM < 1);
my $ack = Ack(3, $NUM);

Просмотреть файл

@ -1,16 +1,16 @@
import sys
sys.setrecursionlimit(5000000)
def Ack(M, N):
if (not M):
return( N + 1 )
if (not N):
return( Ack(M-1, 1) )
return( Ack(M-1, Ack(M, N-1)) )
def main():
NUM = 9
sys.setrecursionlimit(10000)
Ack(3, NUM)
main()
import sys
sys.setrecursionlimit(5000000)
def Ack(M, N):
if (not M):
return( N + 1 )
if (not N):
return( Ack(M-1, 1) )
return( Ack(M-1, Ack(M, N-1)) )
def main():
NUM = 9
sys.setrecursionlimit(10000)
Ack(3, NUM)
main()

Просмотреть файл

@ -1,12 +1,12 @@
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)
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)

Просмотреть файл

@ -1,7 +1,7 @@
(define (ack m n)
(cond ((zero? m) (+ n 1))
((zero? n) (ack (- m 1) 1))
(else (ack (- m 1) (ack m (- n 1))))))
(ack 3 9)
(define (ack m n)
(cond ((zero? m) (+ n 1))
((zero? n) (ack (- m 1) 1))
(else (ack (- m 1) (ack m (- n 1))))))
(ack 3 9)

Просмотреть файл

@ -1,66 +1,66 @@
Bench = %w(
loop
ack
fib
tak
fact
)
Lang = <<EOP.map{|l| l.strip}
ruby-cyg
../../../test6/miniruby
perl
python
gosh
EOP
Bench.replace ['loop2']
Lang.replace ['ruby-cyg']
Ext = %w(
.rb
.rb
.pl
.py
.scm
)
p Bench
p Lang
require 'benchmark'
def bench cmd
m = Benchmark.measure{
#p cmd
system(cmd)
}
[m.utime, m.real]
end
Result = []
Bench.each{|b|
r = []
Lang.each_with_index{|l, idx|
cmd = "#{l} #{b}#{Ext[idx]}"
r << bench(cmd)
}
Result << r
}
require 'pp'
# utime
puts Lang.join("\t")
Bench.each_with_index{|b, bi|
print b, "\t"
puts Result[bi].map{|e| e[0]}.join("\t")
}
# rtime
puts Lang.join("\t")
Bench.each_with_index{|b, bi|
print b, "\t"
puts Result[bi].map{|e| e[1]}.join("\t")
}
Bench = %w(
loop
ack
fib
tak
fact
)
Lang = <<EOP.map{|l| l.strip}
ruby-cyg
../../../test6/miniruby
perl
python
gosh
EOP
Bench.replace ['loop2']
Lang.replace ['ruby-cyg']
Ext = %w(
.rb
.rb
.pl
.py
.scm
)
p Bench
p Lang
require 'benchmark'
def bench cmd
m = Benchmark.measure{
#p cmd
system(cmd)
}
[m.utime, m.real]
end
Result = []
Bench.each{|b|
r = []
Lang.each_with_index{|l, idx|
cmd = "#{l} #{b}#{Ext[idx]}"
r << bench(cmd)
}
Result << r
}
require 'pp'
# utime
puts Lang.join("\t")
Bench.each_with_index{|b, bi|
print b, "\t"
puts Result[bi].map{|e| e[0]}.join("\t")
}
# rtime
puts Lang.join("\t")
Bench.each_with_index{|b, bi|
print b, "\t"
puts Result[bi].map{|e| e[1]}.join("\t")
}

Просмотреть файл

@ -1,13 +1,13 @@
sub fact{
my $n = @_[0];
if($n < 2){
return 1;
}
else{
return $n * fact($n-1);
}
}
for($i=0; $i<10000; $i++){
&fact(100);
}
sub fact{
my $n = @_[0];
if($n < 2){
return 1;
}
else{
return $n * fact($n-1);
}
}
for($i=0; $i<10000; $i++){
&fact(100);
}

Просмотреть файл

@ -1,18 +1,18 @@
#import sys
#sys.setrecursionlimit(1000)
def factL(n):
r = 1
for x in range(2, n):
r *= x
return r
def factR(n):
if n < 2:
return 1
else:
return n * factR(n-1)
for i in range(10000):
factR(100)
#import sys
#sys.setrecursionlimit(1000)
def factL(n):
r = 1
for x in range(2, n):
r *= x
return r
def factR(n):
if n < 2:
return 1
else:
return n * factR(n-1)
for i in range(10000):
factR(100)

Просмотреть файл

@ -1,13 +1,13 @@
def fact(n)
if n < 2
1
else
n * fact(n-1)
end
end
i=0
while i<10000
i+=1
fact(100)
end
def fact(n)
if n < 2
1
else
n * fact(n-1)
end
end
i=0
while i<10000
i+=1
fact(100)
end

Просмотреть файл

@ -1,8 +1,8 @@
(define (fact n)
(if (< n 2)
1
(* n (fact (- n 1)))))
(dotimes (i 10000)
(fact 100))
(define (fact n)
(if (< n 2)
1
(* n (fact (- n 1)))))
(dotimes (i 10000)
(fact 100))

Просмотреть файл

@ -1,11 +1,11 @@
sub fib{
my $n = $_[0];
if($n < 3){
return 1;
}
else{
return fib($n-1) + fib($n-2);
}
};
&fib(34);
sub fib{
my $n = $_[0];
if($n < 3){
return 1;
}
else{
return fib($n-1) + fib($n-2);
}
};
&fib(34);

Просмотреть файл

@ -1,7 +1,7 @@
def fib(n):
if n < 3:
return 1
else:
return fib(n-1) + fib(n-2)
fib(34)
def fib(n):
if n < 3:
return 1
else:
return fib(n-1) + fib(n-2)
fib(34)

Просмотреть файл

@ -1,9 +1,9 @@
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)

Просмотреть файл

@ -1,7 +1,7 @@
(define (fib n)
(if (< n 3)
1
(+ (fib (- n 1)) (fib (- n 2)))))
(fib 34)
(define (fib n)
(if (< n 3)
1
(+ (fib (- n 1)) (fib (- n 2)))))
(fib 34)

Просмотреть файл

@ -1,3 +1,3 @@
for($i=0; $i<30000000; $i++){
}
for($i=0; $i<30000000; $i++){
}

Просмотреть файл

@ -1,2 +1,2 @@
for i in xrange(30000000):
pass
for i in xrange(30000000):
pass

Просмотреть файл

@ -1,4 +1,4 @@
i=0
while i<30000000
i+=1
end
i=0
while i<30000000
i+=1
end

Просмотреть файл

@ -1 +1 @@
(dotimes (x 30000000))
(dotimes (x 30000000))

Просмотреть файл

@ -1 +1 @@
30000000.times{}
30000000.times{}

Просмотреть файл

@ -1,11 +1,11 @@
sub tak {
local($x, $y, $z) = @_;
if (!($y < $x)) {
return $z;
} else {
return &tak(&tak($x - 1, $y, $z),
&tak($y - 1, $z, $x),
&tak($z - 1, $x, $y));
}
}
&tak(18, 9, 0);
sub tak {
local($x, $y, $z) = @_;
if (!($y < $x)) {
return $z;
} else {
return &tak(&tak($x - 1, $y, $z),
&tak($y - 1, $z, $x),
&tak($z - 1, $x, $y));
}
}
&tak(18, 9, 0);

Просмотреть файл

@ -1,8 +1,8 @@
def tak(x, y, z):
if not(y<x):
return z
else:
return tak(tak(x-1, y, z),
tak(y-1, z, x),
tak(z-1, x, y))
tak(18, 9, 0)
def tak(x, y, z):
if not(y<x):
return z
else:
return tak(tak(x-1, y, z),
tak(y-1, z, x),
tak(z-1, x, y))
tak(18, 9, 0)

Просмотреть файл

@ -1,13 +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)
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)

Просмотреть файл

@ -1,10 +1,10 @@
(define (tak x y z)
(if (not (< y x))
z
(tak (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
(tak 18 9 0)
(define (tak x y z)
(if (not (< y x))
z
(tak (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
(tak 18 9 0)

Просмотреть файл

@ -1,81 +1,81 @@
#
# YARV benchmark driver
#
require 'yarvutil'
require 'benchmark'
require 'rbconfig'
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}')
}.utime
rescue Exception => 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
#
# YARV benchmark driver
#
require 'yarvutil'
require 'benchmark'
require 'rbconfig'
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}')
}.utime
rescue Exception => 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

Просмотреть файл

@ -1,123 +1,123 @@
#
# Ruby benchmark driver
#
require 'benchmark'
require 'rbconfig'
$matzrubyonly = 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 $rubyonly || $matzrubyonly
puts "#{bm_name}: "
puts <<EOS unless $matzrubyonly || $rubyonly
#{prog}
--
EOS
begin
result = [bm_name]
result << matzruby_exec(file) unless $rubyonly
result << ruby_exec(file) unless $matzrubyonly
$results << result
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 matzruby_exec file
print 'matz'
benchmark file, $matzruby_program
end
if $0 == __FILE__
ARGV.each{|arg|
case arg
when /\A--ruby=(.+)/
$ruby_program = $1
when /\A--matzruby=(.+)/
$matzruby_program = $1
when /\A--opts=(.+)/
$opts = $1
when /\A(-r|--only-ruby)\z/
$rubyonly = true
when /\A(-m|--only-matzruby)\z/
$matzrubyonly = true
end
}
ARGV.delete_if{|arg|
/\A-/ =~ arg
}
puts "MatzRuby:"
system("#{$matzruby_program} -v")
puts "Ruby:"
system("#{$ruby_program} -v")
puts
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
#
# Ruby benchmark driver
#
require 'benchmark'
require 'rbconfig'
$matzrubyonly = 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 $rubyonly || $matzrubyonly
puts "#{bm_name}: "
puts <<EOS unless $matzrubyonly || $rubyonly
#{prog}
--
EOS
begin
result = [bm_name]
result << matzruby_exec(file) unless $rubyonly
result << ruby_exec(file) unless $matzrubyonly
$results << result
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 matzruby_exec file
print 'matz'
benchmark file, $matzruby_program
end
if $0 == __FILE__
ARGV.each{|arg|
case arg
when /\A--ruby=(.+)/
$ruby_program = $1
when /\A--matzruby=(.+)/
$matzruby_program = $1
when /\A--opts=(.+)/
$opts = $1
when /\A(-r|--only-ruby)\z/
$rubyonly = true
when /\A(-m|--only-matzruby)\z/
$matzrubyonly = true
end
}
ARGV.delete_if{|arg|
/\A-/ =~ arg
}
puts "MatzRuby:"
system("#{$matzruby_program} -v")
puts "Ruby:"
system("#{$ruby_program} -v")
puts
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

Просмотреть файл

@ -1,29 +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
}
#
#
#
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
}

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,429 +1,429 @@
require 'yarvtest/yarvtest'
class TestBlock < YarvTestBase
def test_simple
ae %q(
def m
yield
end
m{
1
}
)
end
def test_param
ae %q(
def m
yield 1
end
m{|ib|
ib*2
}
)
ae %q(
def m
yield 12345, 67890
end
m{|ib,jb|
ib*2+jb
}
)
end
def test_param2
ae %q{
def iter
yield 10
end
a = nil
[iter{|a|
a
}, a]
}
ae %q{
def iter
yield 10
end
iter{|a|
iter{|a|
a + 1
} + a
}
}
ae %q{
def iter
yield 10, 20, 30, 40
end
a = b = c = d = nil
iter{|a, b, c, d|
[a, b, c, d]
} + [a, b, c, d]
}
ae %q{
def iter
yield 10, 20, 30, 40
end
a = b = nil
iter{|a, b, c, d|
[a, b, c, d]
} + [a, b]
}
ae %q{
def iter
yield 10, 20, 30, 40
end
a = nil
iter{|a, $b, @c, d|
[a, $b]
} + [a, $b, @c]
} if false # 1.9 doesn't support expr block parameters
end
def test_param3
if false
# TODO: Ruby 1.9 doesn't support expr block parameter
ae %q{
h = {}
[1].each{|h[:foo]|}
h
}
ae %q{
obj = Object.new
def obj.x=(y)
$ans = y
end
[1].each{|obj.x|}
$ans
}
end
end
def test_blocklocal
ae %q{
1.times{
begin
a = 1
ensure
foo = nil
end
}
}
end
def test_simplenest
ae %q(
def m
yield 123
end
m{|ib|
m{|jb|
ib*jb
}
}
)
end
def test_simplenest2
ae %q(
def m a
yield a
end
m(1){|ib|
m(2){|jb|
ib*jb
}
}
)
end
def test_nest2
ae %q(
def m
yield
end
def n
yield
end
m{
n{
100
}
}
)
ae %q(
def m
yield 1
end
m{|ib|
m{|jb|
i = 20
}
}
)
ae %q(
def m
yield 1
end
m{|ib|
m{|jb|
ib = 20
kb = 2
}
}
)
ae %q(
def iter1
iter2{
yield
}
end
def iter2
yield
end
iter1{
jb = 2
iter1{
jb = 3
}
jb
}
)
ae %q(
def iter1
iter2{
yield
}
end
def iter2
yield
end
iter1{
jb = 2
iter1{
jb
}
jb
}
)
end
def test_ifunc
ae %q{
(1..3).to_a
}
ae %q{
(1..3).map{|e|
e * 4
}
}
ae %q{
class C
include Enumerable
def each
[1,2,3].each{|e|
yield e
}
end
end
C.new.to_a
}
ae %q{
class C
include Enumerable
def each
[1,2,3].each{|e|
yield e
}
end
end
C.new.map{|e|
e + 3
}
}
end
def test_times
ae %q{
sum = 0
3.times{|ib|
2.times{|jb|
sum += ib + jb
}}
sum
}
ae %q{
3.times{|bl|
break 10
}
}
end
def test_for
ae %q{
sum = 0
for x in [1, 2, 3]
sum += x
end
sum
}
ae %q{
sum = 0
for x in (1..5)
sum += x
end
sum
}
ae %q{
sum = 0
for x in []
sum += x
end
sum
}
ae %q{
ans = []
1.times{
for n in 1..3
a = n
ans << a
end
}
}
ae %q{
ans = []
for m in 1..3
for n in 1..3
a = [m, n]
ans << a
end
end
}
end
def test_unmatched_params
ae %q{
def iter
yield 1,2,3
end
iter{|i, j|
[i, j]
}
}
ae %q{
def iter
yield 1
end
iter{|i, j|
[i, j]
}
}
end
def test_rest
# TODO: known bug
#ae %q{
# def iter
# yield 1, 2
# end
#
# iter{|a, |
# [a]
# }
#}
ae %q{
def iter
yield 1, 2
end
iter{|a, *b|
[a, b]
}
}
ae %q{
def iter
yield 1, 2
end
iter{|*a|
[a]
}
}
ae %q{
def iter
yield 1, 2
end
iter{|a, b, *c|
[a, b, c]
}
}
ae %q{
def iter
yield 1, 2
end
iter{|a, b, c, *d|
[a, b, c, d]
}
}
end
def test_param_and_locals
ae %q{
$a = []
def iter
yield 1
end
def m
x = iter{|x|
$a << x
y = 0
}
end
m
$a
}
end
def test_c_break
ae %q{
[1,2,3].find{|x| x == 2}
}
ae %q{
class E
include Enumerable
def each(&block)
[1, 2, 3].each(&block)
end
end
E.new.find {|x| x == 2 }
}
end
end
require 'yarvtest/yarvtest'
class TestBlock < YarvTestBase
def test_simple
ae %q(
def m
yield
end
m{
1
}
)
end
def test_param
ae %q(
def m
yield 1
end
m{|ib|
ib*2
}
)
ae %q(
def m
yield 12345, 67890
end
m{|ib,jb|
ib*2+jb
}
)
end
def test_param2
ae %q{
def iter
yield 10
end
a = nil
[iter{|a|
a
}, a]
}
ae %q{
def iter
yield 10
end
iter{|a|
iter{|a|
a + 1
} + a
}
}
ae %q{
def iter
yield 10, 20, 30, 40
end
a = b = c = d = nil
iter{|a, b, c, d|
[a, b, c, d]
} + [a, b, c, d]
}
ae %q{
def iter
yield 10, 20, 30, 40
end
a = b = nil
iter{|a, b, c, d|
[a, b, c, d]
} + [a, b]
}
ae %q{
def iter
yield 10, 20, 30, 40
end
a = nil
iter{|a, $b, @c, d|
[a, $b]
} + [a, $b, @c]
} if false # 1.9 doesn't support expr block parameters
end
def test_param3
if false
# TODO: Ruby 1.9 doesn't support expr block parameter
ae %q{
h = {}
[1].each{|h[:foo]|}
h
}
ae %q{
obj = Object.new
def obj.x=(y)
$ans = y
end
[1].each{|obj.x|}
$ans
}
end
end
def test_blocklocal
ae %q{
1.times{
begin
a = 1
ensure
foo = nil
end
}
}
end
def test_simplenest
ae %q(
def m
yield 123
end
m{|ib|
m{|jb|
ib*jb
}
}
)
end
def test_simplenest2
ae %q(
def m a
yield a
end
m(1){|ib|
m(2){|jb|
ib*jb
}
}
)
end
def test_nest2
ae %q(
def m
yield
end
def n
yield
end
m{
n{
100
}
}
)
ae %q(
def m
yield 1
end
m{|ib|
m{|jb|
i = 20
}
}
)
ae %q(
def m
yield 1
end
m{|ib|
m{|jb|
ib = 20
kb = 2
}
}
)
ae %q(
def iter1
iter2{
yield
}
end
def iter2
yield
end
iter1{
jb = 2
iter1{
jb = 3
}
jb
}
)
ae %q(
def iter1
iter2{
yield
}
end
def iter2
yield
end
iter1{
jb = 2
iter1{
jb
}
jb
}
)
end
def test_ifunc
ae %q{
(1..3).to_a
}
ae %q{
(1..3).map{|e|
e * 4
}
}
ae %q{
class C
include Enumerable
def each
[1,2,3].each{|e|
yield e
}
end
end
C.new.to_a
}
ae %q{
class C
include Enumerable
def each
[1,2,3].each{|e|
yield e
}
end
end
C.new.map{|e|
e + 3
}
}
end
def test_times
ae %q{
sum = 0
3.times{|ib|
2.times{|jb|
sum += ib + jb
}}
sum
}
ae %q{
3.times{|bl|
break 10
}
}
end
def test_for
ae %q{
sum = 0
for x in [1, 2, 3]
sum += x
end
sum
}
ae %q{
sum = 0
for x in (1..5)
sum += x
end
sum
}
ae %q{
sum = 0
for x in []
sum += x
end
sum
}
ae %q{
ans = []
1.times{
for n in 1..3
a = n
ans << a
end
}
}
ae %q{
ans = []
for m in 1..3
for n in 1..3
a = [m, n]
ans << a
end
end
}
end
def test_unmatched_params
ae %q{
def iter
yield 1,2,3
end
iter{|i, j|
[i, j]
}
}
ae %q{
def iter
yield 1
end
iter{|i, j|
[i, j]
}
}
end
def test_rest
# TODO: known bug
#ae %q{
# def iter
# yield 1, 2
# end
#
# iter{|a, |
# [a]
# }
#}
ae %q{
def iter
yield 1, 2
end
iter{|a, *b|
[a, b]
}
}
ae %q{
def iter
yield 1, 2
end
iter{|*a|
[a]
}
}
ae %q{
def iter
yield 1, 2
end
iter{|a, b, *c|
[a, b, c]
}
}
ae %q{
def iter
yield 1, 2
end
iter{|a, b, c, *d|
[a, b, c, d]
}
}
end
def test_param_and_locals
ae %q{
$a = []
def iter
yield 1
end
def m
x = iter{|x|
$a << x
y = 0
}
end
m
$a
}
end
def test_c_break
ae %q{
[1,2,3].find{|x| x == 2}
}
ae %q{
class E
include Enumerable
def each(&block)
[1, 2, 3].each(&block)
end
end
E.new.find {|x| x == 2 }
}
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,408 +1,408 @@
require 'yarvtest/yarvtest'
class TestException < YarvTestBase
def test_rescue
ae %q{
begin
1
rescue
2
end
}
ae %q{
begin
1
begin
2
rescue
3
end
4
rescue
5
end
}
ae %q{
begin
1
rescue
2
else
3
end
}
end
def test_ensure
ae %q{
begin
1+1
ensure
2+2
end
}
ae %q{
begin
1+1
begin
2+2
ensure
3+3
end
ensure
4+4
end
}
ae %q{
begin
1+1
begin
2+2
ensure
3+3
end
ensure
4+4
begin
5+5
ensure
6+6
end
end
}
end
def test_rescue_ensure
ae %q{
begin
1+1
rescue
2+2
ensure
3+3
end
}
ae %q{
begin
1+1
rescue
2+2
ensure
3+3
end
}
ae %q{
begin
1+1
rescue
2+2
else
3+3
ensure
4+4
end
}
ae %q{
begin
1+1
begin
2+2
rescue
3+3
else
4+4
end
rescue
5+5
else
6+6
ensure
7+7
end
}
end
def test_raise
ae %q{
begin
raise
rescue
:ok
end
}
ae %q{
begin
raise
rescue
:ok
ensure
:ng
end
}
ae %q{
begin
raise
rescue => e
e.class
end
}
ae %q{
begin
raise
rescue StandardError
:ng
rescue Exception
:ok
end
}
ae %q{
begin
begin
raise "a"
rescue
raise "b"
ensure
raise "c"
end
rescue => e
e.message
end
}
end
def test_error_variable
ae %q{
a = nil
1.times{|e|
begin
rescue => err
end
a = err.class
}
}
ae %q{
a = nil
1.times{|e|
begin
raise
rescue => err
end
a = err.class
}
a
}
end
def test_raise_in_other_scope
ae %q{
class E1 < Exception
end
def m
yield
end
begin
begin
begin
m{
raise
}
rescue E1
:ok2
ensure
end
rescue
:ok3
ensure
end
rescue E1
:ok
ensure
end
} do
remove_const :E1
end
ae %q{
$i = 0
def m
iter{
begin
$i += 1
begin
$i += 2
break
ensure
end
ensure
$i += 4
end
$i = 0
}
end
def iter
yield
end
m
$i
}
ae %q{
$i = 0
def m
begin
$i += 1
begin
$i += 2
return
ensure
$i += 3
end
ensure
$i += 4
end
p :end
end
m
$i
}
end
def test_raise_in_cont_sp
ae %q{
def m a, b
a + b
end
m(1, begin
raise
rescue
2
end) +
m(10, begin
raise
rescue
20
ensure
30
end)
}
ae %q{
def m a, b
a + b
end
m(begin
raise
rescue
1
end,
begin
raise
rescue
2
end)
}
end
def test_geterror
ae %q{
$!
}
ae %q{
begin
raise "FOO"
rescue
$!
end
}
ae %q{
def m
$!
end
begin
raise "FOO"
rescue
m()
end
}
ae %q{
$ans = []
def m
$!
end
begin
raise "FOO"
rescue
begin
raise "BAR"
rescue
$ans << m()
end
$ans << m()
end
$ans
}
ae %q{
$ans = []
def m
$!
end
begin
begin
raise "FOO"
ensure
$ans << m()
end
rescue
$ans << m()
end
}
ae %q{
$ans = []
def m
$!
end
def m2
1.times{
begin
return
ensure
$ans << m
end
}
end
m2
$ans
}
end
def test_stack_consistency
ae %q{ #
proc{
begin
raise
break
rescue
:ok
end
}.call
}
ae %q{
proc do
begin
raise StandardError
redo
rescue StandardError
end
end.call
}
end
end
require 'yarvtest/yarvtest'
class TestException < YarvTestBase
def test_rescue
ae %q{
begin
1
rescue
2
end
}
ae %q{
begin
1
begin
2
rescue
3
end
4
rescue
5
end
}
ae %q{
begin
1
rescue
2
else
3
end
}
end
def test_ensure
ae %q{
begin
1+1
ensure
2+2
end
}
ae %q{
begin
1+1
begin
2+2
ensure
3+3
end
ensure
4+4
end
}
ae %q{
begin
1+1
begin
2+2
ensure
3+3
end
ensure
4+4
begin
5+5
ensure
6+6
end
end
}
end
def test_rescue_ensure
ae %q{
begin
1+1
rescue
2+2
ensure
3+3
end
}
ae %q{
begin
1+1
rescue
2+2
ensure
3+3
end
}
ae %q{
begin
1+1
rescue
2+2
else
3+3
ensure
4+4
end
}
ae %q{
begin
1+1
begin
2+2
rescue
3+3
else
4+4
end
rescue
5+5
else
6+6
ensure
7+7
end
}
end
def test_raise
ae %q{
begin
raise
rescue
:ok
end
}
ae %q{
begin
raise
rescue
:ok
ensure
:ng
end
}
ae %q{
begin
raise
rescue => e
e.class
end
}
ae %q{
begin
raise
rescue StandardError
:ng
rescue Exception
:ok
end
}
ae %q{
begin
begin
raise "a"
rescue
raise "b"
ensure
raise "c"
end
rescue => e
e.message
end
}
end
def test_error_variable
ae %q{
a = nil
1.times{|e|
begin
rescue => err
end
a = err.class
}
}
ae %q{
a = nil
1.times{|e|
begin
raise
rescue => err
end
a = err.class
}
a
}
end
def test_raise_in_other_scope
ae %q{
class E1 < Exception
end
def m
yield
end
begin
begin
begin
m{
raise
}
rescue E1
:ok2
ensure
end
rescue
:ok3
ensure
end
rescue E1
:ok
ensure
end
} do
remove_const :E1
end
ae %q{
$i = 0
def m
iter{
begin
$i += 1
begin
$i += 2
break
ensure
end
ensure
$i += 4
end
$i = 0
}
end
def iter
yield
end
m
$i
}
ae %q{
$i = 0
def m
begin
$i += 1
begin
$i += 2
return
ensure
$i += 3
end
ensure
$i += 4
end
p :end
end
m
$i
}
end
def test_raise_in_cont_sp
ae %q{
def m a, b
a + b
end
m(1, begin
raise
rescue
2
end) +
m(10, begin
raise
rescue
20
ensure
30
end)
}
ae %q{
def m a, b
a + b
end
m(begin
raise
rescue
1
end,
begin
raise
rescue
2
end)
}
end
def test_geterror
ae %q{
$!
}
ae %q{
begin
raise "FOO"
rescue
$!
end
}
ae %q{
def m
$!
end
begin
raise "FOO"
rescue
m()
end
}
ae %q{
$ans = []
def m
$!
end
begin
raise "FOO"
rescue
begin
raise "BAR"
rescue
$ans << m()
end
$ans << m()
end
$ans
}
ae %q{
$ans = []
def m
$!
end
begin
begin
raise "FOO"
ensure
$ans << m()
end
rescue
$ans << m()
end
}
ae %q{
$ans = []
def m
$!
end
def m2
1.times{
begin
return
ensure
$ans << m
end
}
end
m2
$ans
}
end
def test_stack_consistency
ae %q{ #
proc{
begin
raise
break
rescue
:ok
end
}.call
}
ae %q{
proc do
begin
raise StandardError
redo
rescue StandardError
end
end.call
}
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,296 +1,296 @@
require 'yarvtest/yarvtest'
class TestJump < YarvTestBase
def test_redo
ae %q{
def m
yield + 10
end
i=0
m{
if i>10
i*i
else
i+=1
redo
end
}
}
end
def test_next
ae %q{
def m
yield
:ok
end
i=0
m{
if i>10
i*i
else
i+=1
next
end
}
}
end
def test_next_with_val
ae %q{
def m
yield
end
m{
next :ok
}
}
end
def test_return
ae %q{
def m
return 3
end
m
}
ae %q{
def m
:ng1
mm{
return :ok
}
:ng2
end
def mm
:ng3
yield
:ng4
end
m
}
end
def test_return2
ae %q{
$i = 0
def m
begin
iter{
return
}
ensure
$i = 100
end
end
def iter
yield
end
m
$i
}
end
def test_return3
ae %q{
def m
begin
raise
rescue
return :ok
end
:ng
end
m
}
end
def test_break
ae %q{
def m
:ng1
mm{
yield
}
:ng2
end
def mm
:ng3
yield
:ng4
end
m{
break :ok
}
}
end
def test_exception_and_break
ae %q{
def m
yield
end
m{
begin
ensure
break :ok
end
}
}
end
def test_retry
# this test can't run on ruby 1.9(yarv can do)
%q{
def m a
mm{
yield
}
end
def mm
yield
end
i=0
m(i+=1){
retry if i<10
:ok
}
}
ae %q{
def m a
yield
end
i=0
m(i+=1){
retry if i<10
:ok
}
}
end
def test_complex_jump
ae %q{
module Enumerable
def all_?
self.each{|e|
unless yield(e)
return false
end
}
true
end
end
xxx = 0
[1,2].each{|bi|
[3,4].each{|bj|
[true, nil, true].all_?{|be| be}
break
}
xxx += 1
}
xxx
}
end
def test_return_from
ae %q{
def m
begin
raise
rescue
return 1
end
end
m
}
ae %q{
def m
begin
#
ensure
return 1
end
end
m
}
end
def test_break_from_times
ae %q{
3.times{
break :ok
}
}
end
def test_catch_and_throw
ae %q{
catch(:foo){
throw :foo
}
}
ae %q{
catch(:foo){
throw :foo, false
}
}
ae %q{
catch(:foo){
throw :foo, nil
}
}
ae %q{
catch(:foo){
throw :foo, :ok
}
}
ae %q{
catch(:foo){
1.times{
throw :foo
}
}
}
ae %q{
catch(:foo){
1.times{
throw :foo, :ok
}
}
}
ae %q{
catch(:foo){
catch(:bar){
throw :foo, :ok
}
:ng
}
}
ae %q{
catch(:foo){
catch(:bar){
1.times{
throw :foo, :ok
}
}
:ng
}
}
end
end
require 'yarvtest/yarvtest'
class TestJump < YarvTestBase
def test_redo
ae %q{
def m
yield + 10
end
i=0
m{
if i>10
i*i
else
i+=1
redo
end
}
}
end
def test_next
ae %q{
def m
yield
:ok
end
i=0
m{
if i>10
i*i
else
i+=1
next
end
}
}
end
def test_next_with_val
ae %q{
def m
yield
end
m{
next :ok
}
}
end
def test_return
ae %q{
def m
return 3
end
m
}
ae %q{
def m
:ng1
mm{
return :ok
}
:ng2
end
def mm
:ng3
yield
:ng4
end
m
}
end
def test_return2
ae %q{
$i = 0
def m
begin
iter{
return
}
ensure
$i = 100
end
end
def iter
yield
end
m
$i
}
end
def test_return3
ae %q{
def m
begin
raise
rescue
return :ok
end
:ng
end
m
}
end
def test_break
ae %q{
def m
:ng1
mm{
yield
}
:ng2
end
def mm
:ng3
yield
:ng4
end
m{
break :ok
}
}
end
def test_exception_and_break
ae %q{
def m
yield
end
m{
begin
ensure
break :ok
end
}
}
end
def test_retry
# this test can't run on ruby 1.9(yarv can do)
%q{
def m a
mm{
yield
}
end
def mm
yield
end
i=0
m(i+=1){
retry if i<10
:ok
}
}
ae %q{
def m a
yield
end
i=0
m(i+=1){
retry if i<10
:ok
}
}
end
def test_complex_jump
ae %q{
module Enumerable
def all_?
self.each{|e|
unless yield(e)
return false
end
}
true
end
end
xxx = 0
[1,2].each{|bi|
[3,4].each{|bj|
[true, nil, true].all_?{|be| be}
break
}
xxx += 1
}
xxx
}
end
def test_return_from
ae %q{
def m
begin
raise
rescue
return 1
end
end
m
}
ae %q{
def m
begin
#
ensure
return 1
end
end
m
}
end
def test_break_from_times
ae %q{
3.times{
break :ok
}
}
end
def test_catch_and_throw
ae %q{
catch(:foo){
throw :foo
}
}
ae %q{
catch(:foo){
throw :foo, false
}
}
ae %q{
catch(:foo){
throw :foo, nil
}
}
ae %q{
catch(:foo){
throw :foo, :ok
}
}
ae %q{
catch(:foo){
1.times{
throw :foo
}
}
}
ae %q{
catch(:foo){
1.times{
throw :foo, :ok
}
}
}
ae %q{
catch(:foo){
catch(:bar){
throw :foo, :ok
}
:ng
}
}
ae %q{
catch(:foo){
catch(:bar){
1.times{
throw :foo, :ok
}
}
:ng
}
}
end
end

Просмотреть файл

@ -1,417 +1,417 @@
require 'yarvtest/yarvtest'
# test of syntax
class TestMassign < YarvTestBase
def test_simle
ae %q{
a = :a; b = :b; c = :c
x, y = a, b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y, z = a, b, c
[x, y, z]
}
end
def test_diff_elems
ae %q{
a = :a ; b = :b ; c = :c
x, y, z = a, b
[x, y, z]
}
ae %q{
a = :a; b = :b; c = :c
x, y = a, b, c
[x, y]
}
end
def test_single_l
ae %q{
a = :a; b = :b
x = a, b
x
}
ae %q{
a = [1, 2]; b = [3, 4]
x = a, b
x
}
end
def test_single_r
ae %q{
a = :a
x, y = a
[x, y]
}
ae %q{
a = [1, 2]
x, y = a
[x, y]
}
ae %q{
a = [1, 2, 3]
x, y = a
[x, y]
}
end
def test_splat_l
ae %q{
a = :a; b = :b; c = :c
*x = a, b
[x]
}
ae %q{
a = :a; b = :b; c = :c
*x = a, b
[x]
}
ae %q{
a = :a; b = :b; c = :c
x, * = a, b
[x]
}
ae %q{
a = :a; b = :b; c = :c
x, *y = a, b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y, *z = a, b
[x, y]
}
ae %q{ # only one item on rhs
*x = :x
x
}
ae %q{ # nil on rhs
*x = nil
x
}
end
def test_splat_r
if false
ae %q{
a = :a; b = :b; c = :c
x, y = *a
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y = a, *b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y = a, b, *c
[x, y]
}
ae %q{
x=*nil
x
}
end
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, y = *a
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, y = a, *b
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, y = a, b, *c
[x, y]
}
end
def test_splat_b1
if false
# error
ae %q{
a = :a; b = :b; c = :c
x, *y = *a
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, *y = a, *b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, *y = a, b, *c
[x, y]
}
end
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, *y = *a
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, *y = a, *b
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, *y = a, b, *c
[x, y]
}
end
def test_splat_b2
if false
# error
ae %q{
a = :a; b = :b; c = :c
*x = *a
x
}
ae %q{
a = :a; b = :b; c = :c
*x = a, *b
x
}
ae %q{
a = :a; b = :b; c = :c
*x = a, b, *c
x
}
end
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
*x = *a
x
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
*x = a, *b
x
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
*x = a, b, *c
x
}
end
def test_toary
ae %q{
x, y = :a
[x, y]
}
ae %q{
x, y = [1, 2]
[x, y]
}
ae %q{
x, y = [1, 2, 3]
[x, y]
}
end
def test_swap
ae %q{
a = 1; b = 2
a, b = b, a
[a, b]
}
end
def test_mret
ae %q{
def m
return 1, 2
end
a, b = m
[a, b]
}
ae %q{
def m
return 1, 2
end
a = m
[a]
}
ae %q{
def m
return 1
end
a, b = m
[a, b]
}
end
def test_mret_splat
if false
ae %q{
def m
return *1
end
a, b = m
[a, b]
}
end
ae %q{
def m
return *[]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1,2]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1,2,3]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1]
end
a = m
}
end
def test_mret_argscat
ae %q{
def m
return 1, *[]
end
a, b = m
[a, b]
}
ae %q{
def m
return 1, 2, *[1]
end
a, b = m
[a, b]
}
ae %q{
def m
return 1, 2, 3, *[1,2]
end
a, b = m
[a, b]
}
end
def test_nested_massign
ae %q{
(a, b), c = [[1, 2], 3]
[a, b, c]
}
ae %q{
a, (b, c) = [[1, 2], 3]
[a, b, c]
}
ae %q{
a, (b, c) = [1, [2, 3]]
[a, b, c]
}
ae %q{
(a, b), *c = [[1, 2], 3]
[a, b, c]
}
ae %q{
(a, b), c, (d, e) = [[1, 2], 3, [4, 5]]
[a, b, c, d, e]
}
ae %q{
(a, *b), c, (d, e, *) = [[1, 2], 3, [4, 5]]
[a, b, c, d, e]
}
ae %q{
(a, b), c, (d, *e) = [[1, 2, 3], 3, [4, 5, 6, 7]]
[a, b, c, d, e]
}
ae %q{
(a, (b1, b2)), c, (d, e) = [[1, 2], 3, [4, 5]]
[a, b1, b2, c, d, e]
}
ae %q{
(a, (b1, b2)), c, (d, e) = [[1, [21, 22]], 3, [4, 5]]
[a, b1, b2, c, d, e]
}
end
# ignore
def _test_massign_value
# Value of this massign statement should be [1, 2, 3]
ae %q{
a, b, c = [1, 2, 3]
}
end
def test_nested_splat
# Somewhat obscure nested splat
ae %q{
a = *[*[1]]
a
}
end
def test_calls_to_a
# Should be result of calling to_a on arg, ie [[1, 2], [3, 4]]
ae %q{
x=*{1=>2,3=>4}
x
}
end
def test_const_massign
ae %q{
class C
class D
end
end
X, Y = 1, 2
Z, C::Const, C::D::Const, ::C::Const2 = 3, 4, 5, 6
[X, Y, Z, C::Const, C::D::Const, ::C::Const2]
}
end
def test_massign_values
ae %q{
ary = [1, 2].partition {|n| n == 1 }
a, b = ary
[a, b]
}
end
end
require 'yarvtest/yarvtest'
# test of syntax
class TestMassign < YarvTestBase
def test_simle
ae %q{
a = :a; b = :b; c = :c
x, y = a, b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y, z = a, b, c
[x, y, z]
}
end
def test_diff_elems
ae %q{
a = :a ; b = :b ; c = :c
x, y, z = a, b
[x, y, z]
}
ae %q{
a = :a; b = :b; c = :c
x, y = a, b, c
[x, y]
}
end
def test_single_l
ae %q{
a = :a; b = :b
x = a, b
x
}
ae %q{
a = [1, 2]; b = [3, 4]
x = a, b
x
}
end
def test_single_r
ae %q{
a = :a
x, y = a
[x, y]
}
ae %q{
a = [1, 2]
x, y = a
[x, y]
}
ae %q{
a = [1, 2, 3]
x, y = a
[x, y]
}
end
def test_splat_l
ae %q{
a = :a; b = :b; c = :c
*x = a, b
[x]
}
ae %q{
a = :a; b = :b; c = :c
*x = a, b
[x]
}
ae %q{
a = :a; b = :b; c = :c
x, * = a, b
[x]
}
ae %q{
a = :a; b = :b; c = :c
x, *y = a, b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y, *z = a, b
[x, y]
}
ae %q{ # only one item on rhs
*x = :x
x
}
ae %q{ # nil on rhs
*x = nil
x
}
end
def test_splat_r
if false
ae %q{
a = :a; b = :b; c = :c
x, y = *a
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y = a, *b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, y = a, b, *c
[x, y]
}
ae %q{
x=*nil
x
}
end
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, y = *a
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, y = a, *b
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, y = a, b, *c
[x, y]
}
end
def test_splat_b1
if false
# error
ae %q{
a = :a; b = :b; c = :c
x, *y = *a
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, *y = a, *b
[x, y]
}
ae %q{
a = :a; b = :b; c = :c
x, *y = a, b, *c
[x, y]
}
end
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, *y = *a
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, *y = a, *b
[x, y]
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
x, *y = a, b, *c
[x, y]
}
end
def test_splat_b2
if false
# error
ae %q{
a = :a; b = :b; c = :c
*x = *a
x
}
ae %q{
a = :a; b = :b; c = :c
*x = a, *b
x
}
ae %q{
a = :a; b = :b; c = :c
*x = a, b, *c
x
}
end
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
*x = *a
x
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
*x = a, *b
x
}
ae %q{
a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
*x = a, b, *c
x
}
end
def test_toary
ae %q{
x, y = :a
[x, y]
}
ae %q{
x, y = [1, 2]
[x, y]
}
ae %q{
x, y = [1, 2, 3]
[x, y]
}
end
def test_swap
ae %q{
a = 1; b = 2
a, b = b, a
[a, b]
}
end
def test_mret
ae %q{
def m
return 1, 2
end
a, b = m
[a, b]
}
ae %q{
def m
return 1, 2
end
a = m
[a]
}
ae %q{
def m
return 1
end
a, b = m
[a, b]
}
end
def test_mret_splat
if false
ae %q{
def m
return *1
end
a, b = m
[a, b]
}
end
ae %q{
def m
return *[]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1,2]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1,2,3]
end
a, b = m
[a, b]
}
ae %q{
def m
return *[1]
end
a = m
}
end
def test_mret_argscat
ae %q{
def m
return 1, *[]
end
a, b = m
[a, b]
}
ae %q{
def m
return 1, 2, *[1]
end
a, b = m
[a, b]
}
ae %q{
def m
return 1, 2, 3, *[1,2]
end
a, b = m
[a, b]
}
end
def test_nested_massign
ae %q{
(a, b), c = [[1, 2], 3]
[a, b, c]
}
ae %q{
a, (b, c) = [[1, 2], 3]
[a, b, c]
}
ae %q{
a, (b, c) = [1, [2, 3]]
[a, b, c]
}
ae %q{
(a, b), *c = [[1, 2], 3]
[a, b, c]
}
ae %q{
(a, b), c, (d, e) = [[1, 2], 3, [4, 5]]
[a, b, c, d, e]
}
ae %q{
(a, *b), c, (d, e, *) = [[1, 2], 3, [4, 5]]
[a, b, c, d, e]
}
ae %q{
(a, b), c, (d, *e) = [[1, 2, 3], 3, [4, 5, 6, 7]]
[a, b, c, d, e]
}
ae %q{
(a, (b1, b2)), c, (d, e) = [[1, 2], 3, [4, 5]]
[a, b1, b2, c, d, e]
}
ae %q{
(a, (b1, b2)), c, (d, e) = [[1, [21, 22]], 3, [4, 5]]
[a, b1, b2, c, d, e]
}
end
# ignore
def _test_massign_value
# Value of this massign statement should be [1, 2, 3]
ae %q{
a, b, c = [1, 2, 3]
}
end
def test_nested_splat
# Somewhat obscure nested splat
ae %q{
a = *[*[1]]
a
}
end
def test_calls_to_a
# Should be result of calling to_a on arg, ie [[1, 2], [3, 4]]
ae %q{
x=*{1=>2,3=>4}
x
}
end
def test_const_massign
ae %q{
class C
class D
end
end
X, Y = 1, 2
Z, C::Const, C::D::Const, ::C::Const2 = 3, 4, 5, 6
[X, Y, Z, C::Const, C::D::Const, ::C::Const2]
}
end
def test_massign_values
ae %q{
ary = [1, 2].partition {|n| n == 1 }
a, b = ary
[a, b]
}
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,118 +1,118 @@
require 'yarvtest/yarvtest'
class TestOpt < YarvTestBase
def test_plus
ae %q{
a, b = 1, 2
a+b
}
ae %q{
class Fixnum
def +(*o)
o
end
def -(*o)
o
end
end
[10+11, 100-101]
}
ae %q{
class Float
def +(o)
self * o
end
end
a, b = 1, 2
a+b
}
end
def test_opt_methdos
klasses = [[Fixnum, 2, 3], [Float, 1.1, 2.2],
[String, "abc", "def"], [Array, [1,2,3], [4, 5]],
[Hash, {:a=>1, :b=>2}, {:x=>"foo", :y=>"bar"}]]
bin_methods = [:+, :-, :*, :/, :%, ]
one_methods = [:length, :succ, ]
ary = []
bin_methods.each{|m|
klasses.each{|klass, obj, arg|
str = %{
ary = []
if (#{obj.inspect}).respond_to? #{m.inspect}
begin
ary << (#{obj.inspect}).#{m.to_s}(#{arg.inspect})
rescue Exception => e
ary << :error
end
end
class #{klass}
def #{m}(o)
[#{m.inspect}, :bin, #{klass}].inspect
end
end
ary << (#{obj.inspect}).#{m.to_s}(#{arg.inspect})
ary
}
ae str
}
}
one_methods.each{|m|
klasses.each{|klass, obj|
str = %{
ary = []
if (#{obj.inspect}).respond_to? #{m.inspect}
ary << (#{obj.inspect}).#{m.to_s}()
end
class #{klass}
def #{m}()
[#{m.inspect}, self, #{klass}].inspect
end
end
ary << (#{obj.inspect}).#{m.to_s}()
ary
}
ae str
}
}
end
def test_opt_plus
ae %q{
temp = 2**30 - 5
(1..5).map do
temp += 1
[temp, temp.class]
end
}
ae %q{
temp = -(2**30 - 5)
(1..10).map do
temp += 1
[temp, temp.class]
end
}
end
def test_eq
ae %q{
class Foo
def ==(other)
true
end
end
foo = Foo.new
[1.0 == foo,
1 == foo,
"abc" == foo,
]
}
end
end
require 'yarvtest/yarvtest'
class TestOpt < YarvTestBase
def test_plus
ae %q{
a, b = 1, 2
a+b
}
ae %q{
class Fixnum
def +(*o)
o
end
def -(*o)
o
end
end
[10+11, 100-101]
}
ae %q{
class Float
def +(o)
self * o
end
end
a, b = 1, 2
a+b
}
end
def test_opt_methdos
klasses = [[Fixnum, 2, 3], [Float, 1.1, 2.2],
[String, "abc", "def"], [Array, [1,2,3], [4, 5]],
[Hash, {:a=>1, :b=>2}, {:x=>"foo", :y=>"bar"}]]
bin_methods = [:+, :-, :*, :/, :%, ]
one_methods = [:length, :succ, ]
ary = []
bin_methods.each{|m|
klasses.each{|klass, obj, arg|
str = %{
ary = []
if (#{obj.inspect}).respond_to? #{m.inspect}
begin
ary << (#{obj.inspect}).#{m.to_s}(#{arg.inspect})
rescue Exception => e
ary << :error
end
end
class #{klass}
def #{m}(o)
[#{m.inspect}, :bin, #{klass}].inspect
end
end
ary << (#{obj.inspect}).#{m.to_s}(#{arg.inspect})
ary
}
ae str
}
}
one_methods.each{|m|
klasses.each{|klass, obj|
str = %{
ary = []
if (#{obj.inspect}).respond_to? #{m.inspect}
ary << (#{obj.inspect}).#{m.to_s}()
end
class #{klass}
def #{m}()
[#{m.inspect}, self, #{klass}].inspect
end
end
ary << (#{obj.inspect}).#{m.to_s}()
ary
}
ae str
}
}
end
def test_opt_plus
ae %q{
temp = 2**30 - 5
(1..5).map do
temp += 1
[temp, temp.class]
end
}
ae %q{
temp = -(2**30 - 5)
(1..10).map do
temp += 1
[temp, temp.class]
end
}
end
def test_eq
ae %q{
class Foo
def ==(other)
true
end
end
foo = Foo.new
[1.0 == foo,
1 == foo,
"abc" == foo,
]
}
end
end

Просмотреть файл

@ -1,293 +1,293 @@
require 'yarvtest/yarvtest'
class TestProc < YarvTestBase
def test_simpleproc
ae %q{
def m(&b)
b
end
m{1}.call
}
ae %q{
def m(&b)
b
end
m{
a = 1
a + 2
}.call
}
end
def test_procarg
ae %q{
def m(&b)
b
end
m{|e_proctest| e_proctest}.call(1)
}
ae %q{
def m(&b)
b
end
m{|e_proctest1, e_proctest2|
a = e_proctest1 * e_proctest2 * 2
a * 3
}.call(1, 2)
}
ae %q{
[
Proc.new{|*args| args}.call(),
Proc.new{|*args| args}.call(1),
Proc.new{|*args| args}.call(1, 2),
Proc.new{|*args| args}.call(1, 2, 3),
]
}
ae %q{
[
Proc.new{|a, *b| [a, b]}.call(),
Proc.new{|a, *b| [a, b]}.call(1),
Proc.new{|a, *b| [a, b]}.call(1, 2),
Proc.new{|a, *b| [a, b]}.call(1, 2, 3),
]
}
end
def test_closure
ae %q{
def make_proc(&b)
b
end
def make_closure
a = 0
make_proc{
a+=1
}
end
cl = make_closure
cl.call + cl.call * cl.call
}
end
def test_nestproc2
ae %q{
def iter
yield
end
def getproc &b
b
end
iter{
bvar = 3
getproc{
bvar2 = 4
bvar * bvar2
}
}.call
}
ae %q{
def iter
yield
end
def getproc &b
b
end
loc1 = 0
pr1 = iter{
bl1 = 1
getproc{
loc1 += 1
bl1 += 1
loc1 + bl1
}
}
pr2 = iter{
bl1 = 1
getproc{
loc1 += 1
bl1 += 1
loc1 + bl1
}
}
pr1.call; pr2.call
pr1.call; pr2.call
pr1.call; pr2.call
(pr1.call + pr2.call) * loc1
}
end
def test_proc_with_cref
ae %q{
Const = :top
class C
Const = :C
$pr = proc{
(1..2).map{
Const
}
}
end
$pr.call
}
ae %q{
Const = :top
class C
Const = :C
end
pr = proc{
Const
}
C.class_eval %q{
pr.call
}
}
end
def test_3nest
ae %q{
def getproc &b
b
end
def m
yield
end
m{
i = 1
m{
j = 2
m{
k = 3
getproc{
[i, j, k]
}
}
}
}.call
}
end
def test_nestproc1
ae %q{
def proc &b
b
end
pr = []
proc{|i_b|
p3 = proc{|j_b|
pr << proc{|k_b|
[i_b, j_b, k_b]
}
}
p3.call(1)
p3.call(2)
}.call(0)
pr[0].call(:last).concat pr[1].call(:last)
}
end
def test_proc_with_block
ae %q{
def proc(&pr)
pr
end
def m
a = 1
m2{
a
}
end
def m2
b = 2
proc{
[yield, b]
}
end
pr = m
x = ['a', 1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,]
pr.call
}
ae %q{
def proc(&pr)
pr
end
def m
a = 1
m2{
a
}
end
def m2
b = 2
proc{
[yield, b]
}
100000.times{|x|
"#{x}"
}
yield
end
m
}
end
def test_method_to_proc
ae %q{
class C
def foo
:ok
end
end
def block
C.method(:new).to_proc
end
b = block()
b.call.foo
}
end
def test_safe
ae %q{
pr = proc{
$SAFE
}
$SAFE = 1
pr.call
}
ae %q{
pr = proc{
$SAFE += 1
}
[pr.call, $SAFE]
}
end
end
require 'yarvtest/yarvtest'
class TestProc < YarvTestBase
def test_simpleproc
ae %q{
def m(&b)
b
end
m{1}.call
}
ae %q{
def m(&b)
b
end
m{
a = 1
a + 2
}.call
}
end
def test_procarg
ae %q{
def m(&b)
b
end
m{|e_proctest| e_proctest}.call(1)
}
ae %q{
def m(&b)
b
end
m{|e_proctest1, e_proctest2|
a = e_proctest1 * e_proctest2 * 2
a * 3
}.call(1, 2)
}
ae %q{
[
Proc.new{|*args| args}.call(),
Proc.new{|*args| args}.call(1),
Proc.new{|*args| args}.call(1, 2),
Proc.new{|*args| args}.call(1, 2, 3),
]
}
ae %q{
[
Proc.new{|a, *b| [a, b]}.call(),
Proc.new{|a, *b| [a, b]}.call(1),
Proc.new{|a, *b| [a, b]}.call(1, 2),
Proc.new{|a, *b| [a, b]}.call(1, 2, 3),
]
}
end
def test_closure
ae %q{
def make_proc(&b)
b
end
def make_closure
a = 0
make_proc{
a+=1
}
end
cl = make_closure
cl.call + cl.call * cl.call
}
end
def test_nestproc2
ae %q{
def iter
yield
end
def getproc &b
b
end
iter{
bvar = 3
getproc{
bvar2 = 4
bvar * bvar2
}
}.call
}
ae %q{
def iter
yield
end
def getproc &b
b
end
loc1 = 0
pr1 = iter{
bl1 = 1
getproc{
loc1 += 1
bl1 += 1
loc1 + bl1
}
}
pr2 = iter{
bl1 = 1
getproc{
loc1 += 1
bl1 += 1
loc1 + bl1
}
}
pr1.call; pr2.call
pr1.call; pr2.call
pr1.call; pr2.call
(pr1.call + pr2.call) * loc1
}
end
def test_proc_with_cref
ae %q{
Const = :top
class C
Const = :C
$pr = proc{
(1..2).map{
Const
}
}
end
$pr.call
}
ae %q{
Const = :top
class C
Const = :C
end
pr = proc{
Const
}
C.class_eval %q{
pr.call
}
}
end
def test_3nest
ae %q{
def getproc &b
b
end
def m
yield
end
m{
i = 1
m{
j = 2
m{
k = 3
getproc{
[i, j, k]
}
}
}
}.call
}
end
def test_nestproc1
ae %q{
def proc &b
b
end
pr = []
proc{|i_b|
p3 = proc{|j_b|
pr << proc{|k_b|
[i_b, j_b, k_b]
}
}
p3.call(1)
p3.call(2)
}.call(0)
pr[0].call(:last).concat pr[1].call(:last)
}
end
def test_proc_with_block
ae %q{
def proc(&pr)
pr
end
def m
a = 1
m2{
a
}
end
def m2
b = 2
proc{
[yield, b]
}
end
pr = m
x = ['a', 1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,
1,2,3,4,5,6,7,8,9,0,]
pr.call
}
ae %q{
def proc(&pr)
pr
end
def m
a = 1
m2{
a
}
end
def m2
b = 2
proc{
[yield, b]
}
100000.times{|x|
"#{x}"
}
yield
end
m
}
end
def test_method_to_proc
ae %q{
class C
def foo
:ok
end
end
def block
C.method(:new).to_proc
end
b = block()
b.call.foo
}
end
def test_safe
ae %q{
pr = proc{
$SAFE
}
$SAFE = 1
pr.call
}
ae %q{
pr = proc{
$SAFE += 1
}
[pr.call, $SAFE]
}
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,8 +1,8 @@
require 'yarvtest/yarvtest'
# test of syntax
class TestTest < YarvTestBase
def test_1
ae '100'
end
end
require 'yarvtest/yarvtest'
# test of syntax
class TestTest < YarvTestBase
def test_1
ae '100'
end
end

Просмотреть файл

@ -1,209 +1,209 @@
require 'yarvtest/yarvtest'
class TestThread < YarvTestBase
def test_create
ae %q{
Thread.new{
}.join
:ok
}
ae %q{
Thread.new{
:ok
}.value
}
end
def test_create_many_threads1
ae %q{
v = 0
(1..200).map{|i|
Thread.new{
i
}
}.each{|t|
v += t.value
}
v
}
end
def test_create_many_threads2
ae %q{
5000.times{|e|
(1..2).map{
Thread.new{
}
}.each{|e|
e.join
}
}
}
end
def test_create_many_threads3
ae %q{
5000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}
}
end
def test_create_many_threads4
ae %q{
100.times{
Thread.new{loop{Thread.pass}}
}
}
end
def test_raise
ae %q{
t = Thread.new{
sleep
}
sleep 0.1
t.raise
begin
t.join
:ng
rescue
:ok
end
}
ae %q{
t = Thread.new{
loop{}
}
Thread.pass
t.raise
begin
t.join
:ng
rescue
:ok
end
}
ae %q{
t = Thread.new{
}
Thread.pass
t.join
t.raise # raise to exited thread
begin
t.join
:ok
rescue
:ng
end
}
end
def test_status
ae %q{
t = Thread.new{
loop{}
}
st = t.status
t.kill
st
}
ae %q{
t = Thread.new{
sleep
}
sleep 0.1
st = t.status
t.kill
st
}
ae %q{
t = Thread.new{
}
t.kill
sleep 0.1
t.status
}
end
def test_tlv
ae %q{
Thread.current[:a] = 1
Thread.new{
Thread.current[:a] = 10
Thread.pass
Thread.current[:a]
}.value + Thread.current[:a]
}
end
def test_thread_group
ae %q{
ptg = Thread.current.group
Thread.new{
ctg = Thread.current.group
[ctg.class, ctg == ptg]
}.value
}
ae %q{
thg = ThreadGroup.new
t = Thread.new{
thg.add Thread.current
sleep
}
sleep 0.1
[thg.list.size, ThreadGroup::Default.list.size]
}
end
def test_thread_local_svar
ae %q{
/a/ =~ 'a'
$a = $~
Thread.new{
$b = $~
/a/ =~ 'a'
$c = $~
}
$d = $~
[$a == $d, $b, $c != $d]
}
end
def test_join
ae %q{
Thread.new{
:ok
}.join.value
}
ae %q{
begin
Thread.new{
raise "ok"
}.join
rescue => e
e
end
}
ae %q{
ans = nil
t = Thread.new{
begin
sleep 0.5
ensure
ans = :ok
end
}
Thread.pass
t.kill
t.join
ans
}
end
end
require 'yarvtest/yarvtest'
class TestThread < YarvTestBase
def test_create
ae %q{
Thread.new{
}.join
:ok
}
ae %q{
Thread.new{
:ok
}.value
}
end
def test_create_many_threads1
ae %q{
v = 0
(1..200).map{|i|
Thread.new{
i
}
}.each{|t|
v += t.value
}
v
}
end
def test_create_many_threads2
ae %q{
5000.times{|e|
(1..2).map{
Thread.new{
}
}.each{|e|
e.join
}
}
}
end
def test_create_many_threads3
ae %q{
5000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}
}
end
def test_create_many_threads4
ae %q{
100.times{
Thread.new{loop{Thread.pass}}
}
}
end
def test_raise
ae %q{
t = Thread.new{
sleep
}
sleep 0.1
t.raise
begin
t.join
:ng
rescue
:ok
end
}
ae %q{
t = Thread.new{
loop{}
}
Thread.pass
t.raise
begin
t.join
:ng
rescue
:ok
end
}
ae %q{
t = Thread.new{
}
Thread.pass
t.join
t.raise # raise to exited thread
begin
t.join
:ok
rescue
:ng
end
}
end
def test_status
ae %q{
t = Thread.new{
loop{}
}
st = t.status
t.kill
st
}
ae %q{
t = Thread.new{
sleep
}
sleep 0.1
st = t.status
t.kill
st
}
ae %q{
t = Thread.new{
}
t.kill
sleep 0.1
t.status
}
end
def test_tlv
ae %q{
Thread.current[:a] = 1
Thread.new{
Thread.current[:a] = 10
Thread.pass
Thread.current[:a]
}.value + Thread.current[:a]
}
end
def test_thread_group
ae %q{
ptg = Thread.current.group
Thread.new{
ctg = Thread.current.group
[ctg.class, ctg == ptg]
}.value
}
ae %q{
thg = ThreadGroup.new
t = Thread.new{
thg.add Thread.current
sleep
}
sleep 0.1
[thg.list.size, ThreadGroup::Default.list.size]
}
end
def test_thread_local_svar
ae %q{
/a/ =~ 'a'
$a = $~
Thread.new{
$b = $~
/a/ =~ 'a'
$c = $~
}
$d = $~
[$a == $d, $b, $c != $d]
}
end
def test_join
ae %q{
Thread.new{
:ok
}.join.value
}
ae %q{
begin
Thread.new{
raise "ok"
}.join
rescue => e
e
end
}
ae %q{
ans = nil
t = Thread.new{
begin
sleep 0.5
ensure
ans = :ok
end
}
Thread.pass
t.kill
t.join
ans
}
end
end

Просмотреть файл

@ -1,207 +1,207 @@
require 'yarvtest/yarvtest'
class TestYield < YarvTestBase
def test_simple
ae %q{
def iter
yield
end
iter{
1
}
}
end
def test_hash_each
ae %q{
h = {:a => 1}
a = []
h.each{|k, v|
a << [k, v]
}
h.each{|kv|
a << kv
}
a
}
end
def test_ary_each
ae %q{
ans = []
ary = [1,2,3]
ary.each{|a, b, c, d|
ans << [a, b, c, d]
}
ary.each{|a, b, c|
ans << [a, b, c]
}
ary.each{|a, b|
ans << [a, b]
}
ary.each{|a|
ans << [a]
}
ans
}
end
def test_iter
ae %q{
def iter *args
yield *args
end
ans = []
ary = [1,2,3]
ary.each{|a, b, c, d|
ans << [a, b, c, d]
}
ary.each{|a, b, c|
ans << [a, b, c]
}
ary.each{|a, b|
ans << [a, b]
}
ary.each{|a|
ans << [a]
}
ans
}
end
def test_iter2
ae %q{
def iter args
yield *args
end
ans = []
iter([]){|a, b|
ans << [a, b]
}
iter([1]){|a, b|
ans << [a, b]
}
iter([1, 2]){|a, b|
ans << [a, b]
}
iter([1, 2, 3]){|a, b|
ans << [a, b]
}
ans
}
ae %q{
def iter args
yield *args
end
ans = []
iter([]){|a|
ans << a
}
iter([1]){|a|
ans << a
}
iter([1, 2]){|a|
ans << a
}
iter([1, 2, 3]){|a|
ans << a
}
ans
}
end
def test_1_ary_and_n_params
ae %q{
def iter args
yield args
end
ans = []
iter([]){|a, b|
ans << [a, b]
}
iter([1]){|a, b|
ans << [a, b]
}
iter([1, 2]){|a, b|
ans << [a, b]
}
iter([1, 2, 3]){|a, b|
ans << [a, b]
}
ans
}
end
def test_1_ary_and_1_params
ae %q{
def iter args
yield args
end
ans = []
iter([]){|a|
ans << a
}
iter([1]){|a|
ans << a
}
iter([1, 2]){|a|
ans << a
}
iter([1, 2, 3]){|a|
ans << a
}
ans
}
end
def test_argscat
ae %q{
def iter
yield 1, *[2, 3]
end
iter{|a, b, c|
[a, b, c]
}
}
ae %q{
def iter
yield 1, *[]
end
iter{|a, b, c|
[a, b, c]
}
}
if false
ae %q{
def iter
yield 1, *2
end
iter{|a, b, c|
[a, b, c]
}
}
end
end
def test_massgin
ae %q{
ans = []
[[1, [2, 3]], [4, [5, 6]]].each{|a, (b, c)|
ans << [a, b, c]
}
ans
}
ae %q{
ans = []
[[1, [2, 3]], [4, [5, 6]]].map{|a, (b, c)|
ans << [a, b, c]
} + ans
}
end
end
require 'yarvtest/yarvtest'
class TestYield < YarvTestBase
def test_simple
ae %q{
def iter
yield
end
iter{
1
}
}
end
def test_hash_each
ae %q{
h = {:a => 1}
a = []
h.each{|k, v|
a << [k, v]
}
h.each{|kv|
a << kv
}
a
}
end
def test_ary_each
ae %q{
ans = []
ary = [1,2,3]
ary.each{|a, b, c, d|
ans << [a, b, c, d]
}
ary.each{|a, b, c|
ans << [a, b, c]
}
ary.each{|a, b|
ans << [a, b]
}
ary.each{|a|
ans << [a]
}
ans
}
end
def test_iter
ae %q{
def iter *args
yield *args
end
ans = []
ary = [1,2,3]
ary.each{|a, b, c, d|
ans << [a, b, c, d]
}
ary.each{|a, b, c|
ans << [a, b, c]
}
ary.each{|a, b|
ans << [a, b]
}
ary.each{|a|
ans << [a]
}
ans
}
end
def test_iter2
ae %q{
def iter args
yield *args
end
ans = []
iter([]){|a, b|
ans << [a, b]
}
iter([1]){|a, b|
ans << [a, b]
}
iter([1, 2]){|a, b|
ans << [a, b]
}
iter([1, 2, 3]){|a, b|
ans << [a, b]
}
ans
}
ae %q{
def iter args
yield *args
end
ans = []
iter([]){|a|
ans << a
}
iter([1]){|a|
ans << a
}
iter([1, 2]){|a|
ans << a
}
iter([1, 2, 3]){|a|
ans << a
}
ans
}
end
def test_1_ary_and_n_params
ae %q{
def iter args
yield args
end
ans = []
iter([]){|a, b|
ans << [a, b]
}
iter([1]){|a, b|
ans << [a, b]
}
iter([1, 2]){|a, b|
ans << [a, b]
}
iter([1, 2, 3]){|a, b|
ans << [a, b]
}
ans
}
end
def test_1_ary_and_1_params
ae %q{
def iter args
yield args
end
ans = []
iter([]){|a|
ans << a
}
iter([1]){|a|
ans << a
}
iter([1, 2]){|a|
ans << a
}
iter([1, 2, 3]){|a|
ans << a
}
ans
}
end
def test_argscat
ae %q{
def iter
yield 1, *[2, 3]
end
iter{|a, b, c|
[a, b, c]
}
}
ae %q{
def iter
yield 1, *[]
end
iter{|a, b, c|
[a, b, c]
}
}
if false
ae %q{
def iter
yield 1, *2
end
iter{|a, b, c|
[a, b, c]
}
}
end
end
def test_massgin
ae %q{
ans = []
[[1, [2, 3]], [4, [5, 6]]].each{|a, (b, c)|
ans << [a, b, c]
}
ans
}
ae %q{
ans = []
[[1, [2, 3]], [4, [5, 6]]].map{|a, (b, c)|
ans << [a, b, c]
} + ans
}
end
end