yarv-dev:391
From: SASADA Koichi <ko1 atdot.net>
Date: Sun, 2 Jan 2005 00:37:03 +0900
Subject: [yarv-dev:391] rev.100
ささだです。
リビジョンを無理やり 100 まであげました。1年間やっててコ
ミットが 100回って少なすぎ。
とりあえず、今までさぼってたところをやりました。
・require
・alias, undef
・svar ($_ とか $~ とか flip flop とか)対応(まだ穴はある)
・super/zsuper(ただし、ブロックの受け渡し・rb_super などは未対応)
・その他
あとは、massign をやるのと、ブロック引数の扱いをまともにす
れば、ある程度 ruby の機能は実現できるんじゃないかと思ってお
ります。(defined? は面倒なのでやらない)
ここまでできたのは、まつもとさんや前田さん、首藤さんをはじ
めとする、ML参加者の方々のご助言のお陰です。
今年もよろしくお願いいたします。
--
// SASADA Koichi at atdot dot net
//
さっきとったベンチマーク:
cpu: celeron 1.4GHz
mem: 256MB
OS : win2k sp2
cc : gcc (GCC) 3.3.3 (cygwin special)
裏で音楽聴いたり irc しながら取ってるので、あんまりあてに
ならない気もします。
/usr/local/bin/ruby_cyg19 -I.. ../benchmark/run.rb
ruby 1.9.0 i386-cygwin(2004-11-29)
YARVCore 0.0.1 rev: 100 (2005-01-01)
[direct threaded code][optimize basic operation][optimize regexp match][stack caching]
-----------------------------------------------------------
block:
def m
yield
end
i=0
while i<10000000
i+=1
m{
}
end
--
user system total real
ruby 15.094000 0.000000 15.094000 ( 15.786000)
yarv 2.812000 0.000000 2.812000 ( 2.917000)
-----------------------------------------------------------
const:
Const = 1
i = 0
while i < 10000000
i+= 1
j = Const
end
--
user system total real
ruby 9.438000 0.000000 9.438000 ( 9.851000)
yarv 0.750000 0.000000 0.750000 ( 0.790000)
-----------------------------------------------------------
ensure:
i=0
while i<1000000
i+=1
begin
begin
ensure
end
ensure
end
end
--
user system total real
ruby 0.797000 0.000000 0.797000 ( 0.860000)
yarv 0.094000 0.000000 0.094000 ( 0.094000)
-----------------------------------------------------------
factorial:
def fact(n)
if(n > 1)
n * fact(n-1)
else
1
end
end
fact(7300)
--
user system total real
ruby 0.735000 0.094000 0.829000 ( 0.927000)
yarv 0.547000 0.063000 0.610000 ( 0.681000)
-----------------------------------------------------------
fib:
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(32)
--
user system total real
ruby 5.844000 0.016000 5.860000 ( 6.135000)
yarv 0.734000 0.000000 0.734000 ( 0.805000)
-----------------------------------------------------------
lists:
#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
NUM = 100
SIZE = 10000
def test_lists()
# create a list of integers (Li1) from 1 to SIZE
li1 = Array.new(SIZE){|i| i+1} # (1..SIZE).to_a
# copy the list to li2 (not by individual items)
li2 = li1.dup
# remove each individual item from left side of li2 and
# append to right side of li3 (preserving order)
li3 = Array.new
while (not li2.empty?)
li3.push(li2.shift)
end
# li2 must now be empty
# remove each individual item from right side of li3 and
# append to right side of li2 (reversing list)
while (not li3.empty?)
li2.push(li3.pop)
end
# li3 must now be empty
# reverse li1 in place
li1.reverse!
# check that first item is now SIZE
if li1[0] != SIZE then
p "not SIZE"
0
else
# compare li1 and li2 for equality
if li1 != li2 then
return(0)
else
# return the length of the list
li1.length
end
end
end
i = 0
while i<NUM
i+=1
result = test_lists()
end
result
--
user system total real
ruby 3.812000 0.000000 3.812000 ( 4.003000)
yarv 2.468000 0.016000 2.484000 ( 2.742000)
-----------------------------------------------------------
method:
def m
end
i=0
while i<10000000
i+=1
m
end
--
user system total real
ruby 11.188000 0.000000 11.188000 ( 11.773000)
yarv 1.750000 0.000000 1.750000 ( 1.886000)
-----------------------------------------------------------
proc:
def m &b
b
end
pr = m{
a = 1
}
i=0
while i<1000000
i+=1
pr.call
end
--
user system total real
ruby 3.390000 0.000000 3.390000 ( 3.561000)
yarv 0.438000 0.031000 0.469000 ( 0.466000)
-----------------------------------------------------------
reccount:
def reccount n
if n > 1
1 + reccount(n-1)
else
1
end
end
reccount 7000
--
user system total real
ruby 0.063000 0.062000 0.125000 ( 0.162000)
yarv 0.000000 0.000000 0.000000 ( 0.006000)
-----------------------------------------------------------
regexp:
i=0
while i<1000000
/hoge/ =~ 'xxxhogexxx'
i+=1
end
--
user system total real
ruby 2.078000 0.016000 2.094000 ( 2.250000)
yarv 1.250000 0.000000 1.250000 ( 1.425000)
-----------------------------------------------------------
rescue:
i=0
while i<10000000
i+=1
begin
rescue
end
end
--
user system total real
ruby 8.843000 0.000000 8.843000 ( 9.268000)
yarv 0.688000 0.000000 0.688000 ( 0.748000)
-----------------------------------------------------------
rescue2:
i=0
while i<100000
i+=1
begin
raise
rescue
end
end
--
user system total real
ruby 3.281000 0.000000 3.281000 ( 3.512000)
yarv 2.047000 0.000000 2.047000 ( 2.136000)
-----------------------------------------------------------
simpleiter:
1000000.times{|simpleiter|
simpleiter
}
--
user system total real
ruby 0.484000 0.000000 0.484000 ( 0.509000)
yarv 0.188000 0.000000 0.188000 ( 0.215000)
-----------------------------------------------------------
simplereturn:
def m
return 1
end
i=0
while i<1000000
i+=1
m
end
--
user system total real
ruby 1.204000 0.000000 1.204000 ( 1.213000)
yarv 0.172000 0.000000 0.172000 ( 0.183000)
-----------------------------------------------------------
so_ackermann:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
def ack(m, n)
if m == 0 then
n + 1
elsif n == 0 then
ack(m - 1, 1)
else
ack(m - 1, ack(m, n - 1))
end
end
NUM = 7
ack(3, NUM)
--
user system total real
ruby 4.250000 0.062000 4.312000 ( 4.738000)
yarv 0.235000 0.000000 0.235000 ( 0.244000)
-----------------------------------------------------------
so_array:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Paul Brannan and Mark Hubbart
n = 9000 # Integer(ARGV.shift || 1)
x = Array.new(n)
y = Array.new(n, 0)
n.times{|bi|
x[bi] = bi + 1
}
(0 .. 999).each do |e|
(n-1).step(0,-1) do |bi|
y[bi] += x.at(bi)
end
end
# puts "#{y.first} #{y.last}"
--
user system total real
ruby 15.406000 0.000000 15.406000 ( 16.057000)
yarv 7.031000 0.000000 7.031000 ( 7.308000)
-----------------------------------------------------------
so_concatenate:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# based on code from Aristarkh A Zagorodnikov and Dat Nguyen
STUFF = "hello\n"
hello = ''
400000.times do |e|
hello << STUFF
end
# puts hello.length
--
user system total real
ruby 0.468000 0.000000 0.468000 ( 0.488000)
yarv 0.203000 0.000000 0.203000 ( 0.222000)
-----------------------------------------------------------
so_count_words:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: wc-ruby.code,v 1.4 2004/11/13 07:43:32 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Paul Brannan
require 'stringio'
input = StringIO.new
data = File.read($DRIVER_PATH + '/wc.input')
5000.times{|i|
input.write data
}
input.seek 0
nl = nw = nc = 0
while true
data = (input.read(4096) or break) << (input.gets || "")
nc += data.length
nl += data.count("\n")
((data.strip! || data).tr!("\n", " ") || data).squeeze!
nw += data.count(" ") + 1
end
# puts "#{nl} #{nw} #{nc}"
--
user system total real
ruby 1.265000 0.172000 1.437000 ( 1.521000)
yarv 1.188000 0.204000 1.392000 ( 1.486000)
-----------------------------------------------------------
so_exception:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
$HI = 0
$LO = 0
NUM = 250000 # Integer(ARGV[0] || 1)
class Lo_Exception < Exception
def initialize(num)
@value = num
end
end
class Hi_Exception < Exception
def initialize(num)
@value = num
end
end
def some_function(num)
begin
hi_function(num)
rescue
print "We shouldn't get here, exception is: #{$!.type}\n"
end
end
def hi_function(num)
begin
lo_function(num)
rescue Hi_Exception
$HI = $HI + 1
end
end
def lo_function(num)
begin
blowup(num)
rescue Lo_Exception
$LO = $LO + 1
end
end
def blowup(num)
if num % 2 == 0
raise Lo_Exception.new(num)
else
raise Hi_Exception.new(num)
end
end
i = 1
max = NUM+1
while i < max
i+=1
some_function(i+1)
end
--
user system total real
ruby 14.156000 0.000000 14.156000 ( 15.245000)
yarv 5.547000 0.000000 5.547000 ( 5.904000)
-----------------------------------------------------------
so_matrix:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
n = 60 #Integer(ARGV.shift || 1)
size = 30
def mkmatrix(rows, cols)
count = 1
mx = Array.new(rows)
(0 .. (rows - 1)).each do |bi|
row = Array.new(cols, 0)
(0 .. (cols - 1)).each do |j|
row[j] = count
count += 1
end
mx[bi] = row
end
mx
end
def mmult(rows, cols, m1, m2)
m3 = Array.new(rows)
(0 .. (rows - 1)).each do |bi|
row = Array.new(cols, 0)
(0 .. (cols - 1)).each do |j|
val = 0
(0 .. (cols - 1)).each do |k|
val += m1.at(bi).at(k) * m2.at(k).at(j)
end
row[j] = val
end
m3[bi] = row
end
m3
end
m1 = mkmatrix(size, size)
m2 = mkmatrix(size, size)
mm = Array.new
n.times do
mm = mmult(size, size, m1, m2)
end
# puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"
--
user system total real
ruby 4.563000 0.000000 4.563000 ( 4.826000)
yarv 1.922000 0.031000 1.953000 ( 2.146000)
-----------------------------------------------------------
so_nested_loop:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# from Avi Bryant
n = 16 # Integer(ARGV.shift || 1)
x = 0
n.times do
n.times do
n.times do
n.times do
n.times do
n.times do
x += 1
end
end
end
end
end
end
# puts x
--
user system total real
ruby 12.109000 0.015000 12.124000 ( 12.619000)
yarv 3.859000 0.016000 3.875000 ( 4.104000)
-----------------------------------------------------------
so_object:
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Aristarkh Zagorodnikov
class Toggle
def initialize(start_state)
@bool = start_state
end
def value
@bool
end
def activate
@bool = !@bool
self
end
end
class NthToggle < Toggle
def initialize(start_state, max_counter)
super start_state
@count_max = max_counter
@counter = 0
end
def activate
@counter += 1
if @counter >= @count_max
@bool = !@bool
@counter = 0
end
self
end
end
n = 1500000 # (ARGV.shift || 1).to_i
toggle = Toggle.new 1
5.times do
puts toggle.activate.value ? 'true' : 'false'
end
n.times do
toggle = Toggle.new 1
end
puts
ntoggle = NthToggle.new 1, 3
8.times do
puts ntoggle.activate.value ? 'true' : 'false'
end
n.times do
ntoggle = NthToggle.new 1, 3
end
--
user system total real
rubyfalse
true
false
true
false
true
true
false
false
false
true
true
true
22.157000 0.032000 22.189000 ( 23.806000)
yarvfalse
true
false
true
false
true
true
false
false
false
true
true
true
20.328000 0.047000 20.375000 ( 22.003000)
-----------------------------------------------------------
so_random:
# from http://www.bagley.org/~doug/shootout/bench/random/random.ruby
IM = 139968
IA = 3877
IC = 29573
$last = 42.0
def gen_random(max)
(max * ($last = ($last * IA + IC) % IM)) / IM
end
N = 1000000
i=0
while i<N
i+=1
gen_random(100.0)
end
# "%.9f" % gen_random(100.0)
--
user system total real
ruby 6.359000 0.000000 6.359000 ( 6.827000)
yarv 4.360000 0.000000 4.360000 ( 4.648000)
-----------------------------------------------------------
so_sieve:
# from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
num = 100
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
--
user system total real
ruby 3.391000 0.016000 3.407000 ( 3.531000)
yarv 0.703000 0.016000 0.719000 ( 0.730000)
-----------------------------------------------------------
strconcat:
i=0
while i<1000000
"#{1+1} #{1+1} #{1+1}"
i+=1
end
--
user system total real
ruby 12.235000 0.000000 12.235000 ( 12.812000)
yarv 10.782000 0.000000 10.782000 ( 11.984000)
-----------------------------------------------------------
super:
class C
def m
1
end
end
class CC < C
def m
super()
end
end
obj = CC.new
i = 0
while i<10000000
obj.m
i+=1
end
--
user system total real
ruby 17.735000 0.000000 17.735000 ( 18.750000)
yarv 4.235000 0.000000 4.235000 ( 4.433000)
-----------------------------------------------------------
tak:
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)
--
user system total real
ruby 19.047000 0.000000 19.047000 ( 20.186000)
yarv 3.093000 0.000000 3.093000 ( 3.304000)
-----------------------------------------------------------
tarai:
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)
--
user system total real
ruby 15.203000 0.032000 15.235000 ( 16.349000)
yarv 3.578000 0.000000 3.578000 ( 3.835000)
-----------------------------------------------------------
times:
10000000.times{|i|
}
--
user system total real
ruby 3.782000 0.000000 3.782000 ( 4.004000)
yarv 1.859000 0.000000 1.859000 ( 1.936000)
-----------------------------------------------------------
whileloop:
i = 0
while i<10000000
i+=1
end
--
user system total real
ruby 6.953000 0.000000 6.953000 ( 7.301000)
yarv 0.609000 0.000000 0.609000 ( 0.669000)
-----------------------------------------------------------
zsuper:
i = 0
class C
def m a
1
end
end
class CC < C
def m a
super
end
end
obj = CC.new
while i<10000000
obj.m 10
i+=1
end
--
user system total real
ruby 18.093000 0.000000 18.093000 ( 19.095000)
yarv 4.500000 0.000000 4.500000 ( 4.788000)
--
ML: yarv-dev quickml.atdot.net
使い方: http://www.atdot.net/~ko1/quickml