2014-01-26 00:31:36 +0000
target 0: ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] at "ruby --disable=gems"
target 1: built-ruby (ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux]) at "./ruby -I../lib -I. -I.ext/common --disable-gems"
-----------------------------------------------------------
app_answer
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
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.033555281
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.033357323
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.03352264
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.033245331
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.033291459
built-ruby 0.033755607
built-ruby 0.033715242
built-ruby 0.033701039
built-ruby 0.033740448
built-ruby 0.033740431
-----------------------------------------------------------
app_aobench
# AO rebder benchmark
# Original program (C) Syoyo Fujita in Javascript (and other languages)
# http://lucille.atso-net.jp/blog/?p=642
# http://lucille.atso-net.jp/blog/?p=711
# Ruby(yarv2llvm) version by Hideki Miura
#
IMAGE_WIDTH = 256
IMAGE_HEIGHT = 256
NSUBSAMPLES = 2
NAO_SAMPLES = 8
class Vec
def initialize(x, y, z)
@x = x
@y = y
@z = z
end
attr_accessor :x, :y, :z
def vadd(b)
Vec.new(@x + b.x, @y + b.y, @z + b.z)
end
def vsub(b)
Vec.new(@x - b.x, @y - b.y, @z - b.z)
end
def vcross(b)
Vec.new(@y * b.z - @z * b.y,
@z * b.x - @x * b.z,
@x * b.y - @y * b.x)
end
def vdot(b)
@x * b.x + @y * b.y + @z * b.z
end
def vlength
Math.sqrt(@x * @x + @y * @y + @z * @z)
end
def vnormalize
len = vlength
v = Vec.new(@x, @y, @z)
if len > 1.0e-17 then
v.x = v.x / len
v.y = v.y / len
v.z = v.z / len
end
v
end
end
class Sphere
def initialize(center, radius)
@center = center
@radius = radius
end
attr_reader :center, :radius
def intersect(ray, isect)
rs = ray.org.vsub(@center)
b = rs.vdot(ray.dir)
c = rs.vdot(rs) - (@radius * @radius)
d = b * b - c
if d > 0.0 then
t = - b - Math.sqrt(d)
if t > 0.0 and t < isect.t then
isect.t = t
isect.hit = true
isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
ray.org.y + ray.dir.y * t,
ray.org.z + ray.dir.z * t)
n = isect.pl.vsub(@center)
isect.n = n.vnormalize
else
0.0
end
end
nil
end
end
class Plane
def initialize(p, n)
@p = p
@n = n
end
def intersect(ray, isect)
d = -@p.vdot(@n)
v = ray.dir.vdot(@n)
v0 = v
if v < 0.0 then
v0 = -v
end
if v0 < 1.0e-17 then
return
end
t = -(ray.org.vdot(@n) + d) / v
if t > 0.0 and t < isect.t then
isect.hit = true
isect.t = t
isect.n = @n
isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
ray.org.y + t * ray.dir.y,
ray.org.z + t * ray.dir.z)
end
nil
end
end
class Ray
def initialize(org, dir)
@org = org
@dir = dir
end
attr_accessor :org, :dir
end
class Isect
def initialize
@t = 10000000.0
@hit = false
@pl = Vec.new(0.0, 0.0, 0.0)
@n = Vec.new(0.0, 0.0, 0.0)
end
attr_accessor :t, :hit, :pl, :n
end
def clamp(f)
i = f * 255.5
if i > 255.0 then
i = 255.0
end
if i < 0.0 then
i = 0.0
end
i.to_i
end
def otherBasis(basis, n)
basis[2] = Vec.new(n.x, n.y, n.z)
basis[1] = Vec.new(0.0, 0.0, 0.0)
if n.x < 0.6 and n.x > -0.6 then
basis[1].x = 1.0
elsif n.y < 0.6 and n.y > -0.6 then
basis[1].y = 1.0
elsif n.z < 0.6 and n.z > -0.6 then
basis[1].z = 1.0
else
basis[1].x = 1.0
end
basis[0] = basis[1].vcross(basis[2])
basis[0] = basis[0].vnormalize
basis[1] = basis[2].vcross(basis[0])
basis[1] = basis[1].vnormalize
end
class Scene
def initialize
@spheres = Array.new
@spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5)
@spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5)
@spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5)
@plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0))
end
def ambient_occlusion(isect)
basis = Array.new
otherBasis(basis, isect.n)
ntheta = NAO_SAMPLES
nphi = NAO_SAMPLES
eps = 0.0001
occlusion = 0.0
p0 = Vec.new(isect.pl.x + eps * isect.n.x,
isect.pl.y + eps * isect.n.y,
isect.pl.z + eps * isect.n.z)
nphi.times do |j|
ntheta.times do |i|
r = rand
phi = 2.0 * 3.14159265 * rand
x = Math.cos(phi) * Math.sqrt(1.0 - r)
y = Math.sin(phi) * Math.sqrt(1.0 - r)
z = Math.sqrt(r)
rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
rz = x * basis[0].z + y * basis[1].z + z * basis[2].z
raydir = Vec.new(rx, ry, rz)
ray = Ray.new(p0, raydir)
occisect = Isect.new
@spheres[0].intersect(ray, occisect)
@spheres[1].intersect(ray, occisect)
@spheres[2].intersect(ray, occisect)
@plane.intersect(ray, occisect)
if occisect.hit then
occlusion = occlusion + 1.0
else
0.0
end
end
end
occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f)
Vec.new(occlusion, occlusion, occlusion)
end
def render(w, h, nsubsamples)
cnt = 0
nsf = nsubsamples.to_f
h.times do |y|
w.times do |x|
rad = Vec.new(0.0, 0.0, 0.0)
# Subsmpling
nsubsamples.times do |v|
nsubsamples.times do |u|
cnt = cnt + 1
wf = w.to_f
hf = h.to_f
xf = x.to_f
yf = y.to_f
uf = u.to_f
vf = v.to_f
px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)
eye = Vec.new(px, py, -1.0).vnormalize
ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)
isect = Isect.new
@spheres[0].intersect(ray, isect)
@spheres[1].intersect(ray, isect)
@spheres[2].intersect(ray, isect)
@plane.intersect(ray, isect)
if isect.hit then
col = ambient_occlusion(isect)
rad.x = rad.x + col.x
rad.y = rad.y + col.y
rad.z = rad.z + col.z
end
end
end
r = rad.x / (nsf * nsf)
g = rad.y / (nsf * nsf)
b = rad.z / (nsf * nsf)
printf("%c", clamp(r))
printf("%c", clamp(g))
printf("%c", clamp(b))
end
nil
end
nil
end
end
alias printf_orig printf
def printf *args
end
# File.open("ao.ppm", "w") do |fp|
printf("P6\n")
printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT)
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
# end
undef printf
alias printf printf_orig
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 37.943114181
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 37.635535388
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 37.991318301
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 37.573186748
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 37.842966131
built-ruby 37.121201651
built-ruby 37.465089728
built-ruby 37.62565274
built-ruby 37.388670022
built-ruby 37.576921739
-----------------------------------------------------------
app_erb
#
# Create many HTML strings with ERB.
#
require 'erb'
data = DATA.read
max = 15_000
title = "hello world!"
content = "hello world!\n" * 10
max.times{
ERB.new(data).result(binding)
}
__END__
<%= title %>
<%= title %>
<%= content %>
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.789711954
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.777640736
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.781928973
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.793688773
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.813961813
built-ruby 0.767211053
built-ruby 0.74452762
built-ruby 0.750127388
built-ruby 0.749309243
built-ruby 0.858333308
-----------------------------------------------------------
app_factorial
def fact(n)
if(n > 1)
n * fact(n-1)
else
1
end
end
100.times {
fact(5000)
}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.667314485
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.855201569
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.660050023
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.663853299
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.660658355
built-ruby 0.755377944
built-ruby 0.808489243
built-ruby 0.759559218
built-ruby 0.790604089
built-ruby 0.788595964
-----------------------------------------------------------
app_fib
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.413086575
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.41520995
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.413459552
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.412696851
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.423780057
built-ruby 0.415677737
built-ruby 0.426366817
built-ruby 0.41592031
built-ruby 0.422772283
built-ruby 0.416415745
-----------------------------------------------------------
app_mandelbrot
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..1000).each{|dx|
(0..1000).each{|dy|
x = dx / 50.0
y = dy / 50.0
c = Complex(x, y)
ary << c if mandelbrot?(c)
}
}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.827876136
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.841940049
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.828424173
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.829778375
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.828756231
built-ruby 0.847413282
built-ruby 0.81891856
built-ruby 0.819717904
built-ruby 0.838023681
built-ruby 0.842269346
-----------------------------------------------------------
app_pentomino
#!/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)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.796860252
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.814994442
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.814929389
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.981255243
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 13.061041398
built-ruby 12.526663867
built-ruby 12.512981105
built-ruby 12.521167999
built-ruby 12.584003492
built-ruby 12.772697618
-----------------------------------------------------------
app_raise
i = 0
while i<300000
i += 1
begin
raise
rescue
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.245770362
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.244296721
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.242882609
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.244873584
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.246824287
built-ruby 0.251414191
built-ruby 0.289111129
built-ruby 0.24993796
built-ruby 0.250494997
built-ruby 0.248938525
-----------------------------------------------------------
app_strconcat
i = 0
while i<2_000_000
"#{1+1} #{1+1} #{1+1}"
i += 1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.899768523
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.899889922
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.900119293
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.899482422
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.900276832
built-ruby 0.894555957
built-ruby 0.896957904
built-ruby 0.894714663
built-ruby 0.894237131
built-ruby 0.900236595
-----------------------------------------------------------
app_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)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.57786976
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.576610459
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.57614403
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.577749968
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.577909959
built-ruby 0.585955079
built-ruby 0.597077077
built-ruby 0.586149879
built-ruby 0.604947901
built-ruby 0.585982093
-----------------------------------------------------------
app_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)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.478156448
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.479722763
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.478451311
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.479515893
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.483619755
built-ruby 0.481131113
built-ruby 0.48558884
built-ruby 0.478262373
built-ruby 0.477802233
built-ruby 0.477256869
-----------------------------------------------------------
app_uri
require 'uri'
100_000.times{
uri = URI.parse('http://www.ruby-lang.org')
uri.scheme
uri.host
uri.port
}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.487728554
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.484377413
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.490704557
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.480049866
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.480737481
built-ruby 0.492252563
built-ruby 0.49582392
built-ruby 0.49210717
built-ruby 0.496187603
built-ruby 0.498262986
-----------------------------------------------------------
hash_flatten
h = {}
10000.times do |i|
h[i] = nil
end
1000.times do
h.flatten
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.507664698
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.505701922
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.50719556
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.508784227
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.502714638
built-ruby 0.488798628
built-ruby 0.488623761
built-ruby 0.491566609
built-ruby 0.487702663
built-ruby 0.489886472
-----------------------------------------------------------
hash_keys
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.keys
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.1953046
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.193480569
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.192985145
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.193331055
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.195412564
built-ruby 0.212517791
built-ruby 0.21233361
built-ruby 0.21296214
built-ruby 0.212167405
built-ruby 0.212481111
-----------------------------------------------------------
hash_shift
h = {}
10000.times do |i|
h[i] = nil
end
50000.times do
k, v = h.shift
h[k] = v
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.020105266
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.019831522
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.019590215
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.019301037
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.019375203
built-ruby 0.019521662
built-ruby 0.019508311
built-ruby 0.019567089
built-ruby 0.019504154
built-ruby 0.019586695
-----------------------------------------------------------
hash_values
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.values
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.203233942
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.202347865
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.202541242
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.202444551
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.204208976
built-ruby 0.217975964
built-ruby 0.217646828
built-ruby 0.216964019
built-ruby 0.21722573
built-ruby 0.21959706
-----------------------------------------------------------
io_file_create
#
# Create files
#
max = 200_000
file = './tmpfile_of_bm_io_file_create'
max.times{
f = open(file, 'w')
f.close#(true)
}
File.unlink(file)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.053196524
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.069939707
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.050157621
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.059099717
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.049847334
built-ruby 1.10577207
built-ruby 1.060766017
built-ruby 1.050701378
built-ruby 1.043612966
built-ruby 1.039796447
-----------------------------------------------------------
io_file_read
#
# Seek and Read file.
#
require 'tempfile'
max = 200_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')
f.write str
max.times{
f.seek 0
f.read
}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.030491138
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.024917585
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.042347705
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.085087246
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.000406307
built-ruby 1.681778215
built-ruby 1.675241769
built-ruby 1.737014709
built-ruby 1.753662329
built-ruby 1.717389054
-----------------------------------------------------------
io_file_write
#
# Seek and Write file.
#
require 'tempfile'
max = 200_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')
max.times{
f.seek 0
f.write str
}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.795429468
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.728081767
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.886236209
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.74377026
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.712752278
built-ruby 0.692689165
built-ruby 0.694980257
built-ruby 0.684498835
built-ruby 0.688804379
built-ruby 0.699688474
-----------------------------------------------------------
io_select
# IO.select performance
w = [ IO.pipe[1] ];
nr = 1000000
nr.times {
IO.select nil, w
}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.211566244
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.225696283
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.232177507
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.21885029
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.224931972
built-ruby 1.167430379
built-ruby 1.174573892
built-ruby 1.182789841
built-ruby 1.162456028
built-ruby 1.177353581
-----------------------------------------------------------
io_select2
# IO.select performance. worst case of single fd.
ios = []
nr = 1000000
if defined?(Process::RLIMIT_NOFILE)
max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
else
max = 64
end
puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
((max / 2) - 10).times do
ios.concat IO.pipe
end
last = [ ios[-1] ]
puts "last IO: #{last[0].inspect}"
nr.times do
IO.select nil, last
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.341722176
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.352318597
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.339076852
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.354753797
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.352473936
built-ruby 1.327035646
built-ruby 1.314175852
built-ruby 1.307582278
built-ruby 1.30751438
built-ruby 1.32719513
-----------------------------------------------------------
io_select3
# IO.select performance. a lot of fd
ios = []
nr = 100
if defined?(Process::RLIMIT_NOFILE)
max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
else
max = 64
end
puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
(max - 10).times do
r, w = IO.pipe
r.close
ios.push w
end
nr.times do
IO.select nil, ios
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.0163473
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.016298826
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.01619833
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.016137586
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.016393813
built-ruby 0.01647956
built-ruby 0.016475676
built-ruby 0.016740095
built-ruby 0.016550961
built-ruby 0.0163982
-----------------------------------------------------------
loop_for
for i in 1..30_000_000
#
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.070012589
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.129359709
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.034065961
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.003143597
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.08130685
built-ruby 1.017249744
built-ruby 0.999233462
built-ruby 1.00740022
built-ruby 0.999712273
built-ruby 1.123709897
-----------------------------------------------------------
loop_generator
max = 600000
if defined? Fiber
gen = (1..max).each
loop do
gen.next
end
else
require 'generator'
gen = Generator.new((0..max))
while gen.next?
gen.next
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.637752224
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.643288055
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.637375185
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.653735802
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.649378894
built-ruby 0.628572037
built-ruby 0.628724518
built-ruby 0.628660768
built-ruby 0.630606119
built-ruby 0.628508035
-----------------------------------------------------------
loop_times
30_000_000.times{|e|}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.924747834
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.924528086
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.923091906
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.929812108
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.929765409
built-ruby 0.91939562
built-ruby 0.919421691
built-ruby 0.940609266
built-ruby 0.920566508
built-ruby 0.920739799
-----------------------------------------------------------
loop_whileloop
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.437014805
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.43676648
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.436832328
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.436828711
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.436744876
built-ruby 0.445582992
built-ruby 0.44963972
built-ruby 0.448655436
built-ruby 0.446364092
built-ruby 0.446898428
-----------------------------------------------------------
loop_whileloop2
i = 0
while i< 6_000_000 # benchmark loop 2
i += 1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.090736606
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.091216426
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.090630608
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.090346074
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.090378588
built-ruby 0.092643515
built-ruby 0.092917025
built-ruby 0.092870716
built-ruby 0.092798683
built-ruby 0.093384157
-----------------------------------------------------------
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 = 9
ack(3, NUM)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.480243235
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.486571961
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.481927785
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.484448545
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.493851759
built-ruby 0.4952896
built-ruby 0.498071422
built-ruby 0.489745806
built-ruby 0.484355391
built-ruby 0.495220883
-----------------------------------------------------------
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}"
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.713034066
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.708972822
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.713908051
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.730485875
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.716424186
built-ruby 0.71332656
built-ruby 0.709869855
built-ruby 0.701754895
built-ruby 0.697279615
built-ruby 0.698964444
-----------------------------------------------------------
so_binary_trees
# The Computer Language Shootout Benchmarks
# http://shootout.alioth.debian.org
#
# contributed by Jesse Millikan
# disable output
alias puts_orig puts
def puts str
# disable puts
end
def item_check(tree)
if tree[0] == nil
tree[1]
else
tree[1] + item_check(tree[0]) - item_check(tree[2])
end
end
def bottom_up_tree(item, depth)
if depth > 0
item_item = 2 * item
depth -= 1
[bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
else
[nil, item, nil]
end
end
max_depth = 16 # ARGV[0].to_i
min_depth = 4
max_depth = min_depth + 2 if min_depth + 2 > max_depth
stretch_depth = max_depth + 1
stretch_tree = bottom_up_tree(0, stretch_depth)
puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
stretch_tree = nil
long_lived_tree = bottom_up_tree(0, max_depth)
min_depth.step(max_depth + 1, 2) do |depth|
iterations = 2**(max_depth - depth + min_depth)
check = 0
for i in 1..iterations
temp_tree = bottom_up_tree(i, depth)
check += item_check(temp_tree)
temp_tree = bottom_up_tree(-i, depth)
check += item_check(temp_tree)
end
puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
end
puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"
undef puts
alias puts puts_orig
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.228835163
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.19859686
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.222984643
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.198026852
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.215995895
built-ruby 5.148985291
built-ruby 5.191428982
built-ruby 5.140686107
built-ruby 5.172637299
built-ruby 5.198782439
-----------------------------------------------------------
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"
i = 0
while i<10
i += 1
hello = ''
4_000_000.times do |e|
hello << STUFF
end
end
# puts hello.length
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.2972382
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.287191866
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.662107489
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.347875068
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.451565112
built-ruby 3.293970317
built-ruby 3.292595835
built-ruby 3.29321435
built-ruby 3.292261961
built-ruby 3.293631189
-----------------------------------------------------------
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
input = open(File.join(File.dirname($0), 'wc.input'), 'rb')
nl = nw = nc = 0
while true
tmp = input.read(4096) or break
data = tmp << (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}"
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.15532526
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.155208746
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.155230237
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.156223252
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.155306338
built-ruby 0.174373349
built-ruby 0.172708567
built-ruby 0.174499774
built-ruby 0.174482247
built-ruby 0.175391228
-----------------------------------------------------------
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
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.233828219
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.23432766
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.234052579
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.233772835
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.244158274
built-ruby 0.244240919
built-ruby 0.242222265
built-ruby 0.238443383
built-ruby 0.245105819
built-ruby 0.243901079
-----------------------------------------------------------
so_fannkuch
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura
# Modified by Ryan Williams
def fannkuch(n)
maxFlips, m, r, check = 0, n-1, n, 0
count = (1..n).to_a
perm = (1..n).to_a
while true
if check < 30
puts "#{perm}"
check += 1
end
while r != 1
count[r-1] = r
r -= 1
end
if perm[0] != 1 and perm[m] != n
perml = perm.clone #.dup
flips = 0
while (k = perml.first ) != 1
perml = perml.slice!(0, k).reverse + perml
flips += 1
end
maxFlips = flips if flips > maxFlips
end
while true
if r==n then return maxFlips end
perm.insert r,perm.shift
break if (count[r] -= 1) > 0
r += 1
end
end
end
def puts *args
end
N = 9 # (ARGV[0] || 1).to_i
puts "Pfannkuchen(#{N}) = #{fannkuch(N)}"
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.882880352
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.874691007
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.874351962
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.87070121
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.887421513
built-ruby 0.913476839
built-ruby 0.909053428
built-ruby 0.909953984
built-ruby 0.913176183
built-ruby 0.907222353
-----------------------------------------------------------
so_fasta
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura
$last = 42.0
def gen_random (max,im=139968,ia=3877,ic=29573)
(max * ($last = ($last * ia + ic) % im)) / im
end
alu =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"
iub = [
["a", 0.27],
["c", 0.12],
["g", 0.12],
["t", 0.27],
["B", 0.02],
["D", 0.02],
["H", 0.02],
["K", 0.02],
["M", 0.02],
["N", 0.02],
["R", 0.02],
["S", 0.02],
["V", 0.02],
["W", 0.02],
["Y", 0.02],
]
homosapiens = [
["a", 0.3029549426680],
["c", 0.1979883004921],
["g", 0.1975473066391],
["t", 0.3015094502008],
]
def make_repeat_fasta(id, desc, src, n)
puts ">#{id} #{desc}"
v = nil
width = 60
l = src.length
s = src * ((n / l) + 1)
s.slice!(n, l)
puts(s.scan(/.{1,#{width}}/).join("\n"))
end
def make_random_fasta(id, desc, table, n)
puts ">#{id} #{desc}"
rand, v = nil,nil
width = 60
chunk = 1 * width
prob = 0.0
table.each{|v| v[1]= (prob += v[1])}
for i in 1..(n/width)
puts((1..width).collect{
rand = gen_random(1.0)
table.find{|v| v[1]>rand}[0]
}.join)
end
if n%width != 0
puts((1..(n%width)).collect{
rand = gen_random(1.0)
table.find{|v| v[1]>rand}[0]
}.join)
end
end
n = (ARGV[0] or 250_000).to_i
make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.412494596
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.41141201
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.409073303
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.410537872
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.410502034
built-ruby 1.438079807
built-ruby 1.405574484
built-ruby 1.413909002
built-ruby 1.402070667
built-ruby 1.402692819
-----------------------------------------------------------
so_k_nucleotide
# The Computer Language Shootout
# http://shootout.alioth.debian.org
#
# contributed by jose fco. gonzalez
# modified by Sokolov Yura
seq = String.new
def frecuency( seq,length )
n, table = seq.length - length + 1, Hash.new(0)
f, i = nil, nil
(0 ... length).each do |f|
(f ... n).step(length) do |i|
table[seq[i,length]] += 1
end
end
[n,table]
end
def sort_by_freq( seq,length )
n,table = frecuency( seq,length )
a, b, v = nil, nil, nil
table.sort{|a,b| b[1] <=> a[1]}.each do |v|
puts "%s %.3f" % [v[0].upcase,((v[1]*100).to_f/n)]
end
puts
end
def find_seq( seq,s )
n,table = frecuency( seq,s.length )
puts "#{table[s].to_s}\t#{s.upcase}"
end
input = open(File.join(File.dirname($0), 'fasta.output.100000'), 'rb')
line = input.gets while line !~ /^>THREE/
line = input.gets
while (line !~ /^>/) & line do
seq << line.chomp
line = input.gets
end
[1,2].each {|i| sort_by_freq( seq,i ) }
%w(ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt).each{|s| find_seq( seq,s) }
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.947495162
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.948217404
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.97135431
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.955350848
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.955091117
built-ruby 0.927221734
built-ruby 0.925033171
built-ruby 0.919092172
built-ruby 0.919021977
built-ruby 0.919478531
-----------------------------------------------------------
so_lists
#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
NUM = 300
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 LIMIT_SQUARED
escape = true
break
end
end
byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
bit_num += 1
# Code is very similar for these cases, but using separate blocks
# ensures we skip the shifting when it's unnecessary, which is most cases.
if (bit_num == 8)
print byte_acc.chr
byte_acc = 0
bit_num = 0
elsif (x == count_size)
byte_acc <<= (8 - bit_num)
print byte_acc.chr
byte_acc = 0
bit_num = 0
end
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.850816987
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.87868801
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.903115673
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.873466627
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.888000948
built-ruby 2.010814144
built-ruby 1.863635001
built-ruby 1.854873195
built-ruby 1.890932312
built-ruby 1.854646928
-----------------------------------------------------------
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 = 40
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]}"
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.441456912
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.442198802
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.442727001
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.449729945
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.441800903
built-ruby 0.445645146
built-ruby 0.440948552
built-ruby 0.457685022
built-ruby 0.446768414
built-ruby 0.44223566
-----------------------------------------------------------
so_meteor_contest
#!/usr/bin/env ruby
#
# The Computer Language Shootout
# http://shootout.alioth.debian.org
# contributed by Kevin Barnes (Ruby novice)
# PROGRAM: the main body is at the bottom.
# 1) read about the problem here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/
# 2) see how I represent a board as a bitmask by reading the blank_board comments
# 3) read as your mental paths take you
def print *args
end
# class to represent all information about a particular rotation of a particular piece
class Rotation
# an array (by location) containing a bit mask for how the piece maps at the given location.
# if the rotation is invalid at that location the mask will contain false
attr_reader :start_masks
# maps a direction to a relative location. these differ depending on whether it is an even or
# odd row being mapped from
@@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 }
@@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 }
def initialize( directions )
@even_offsets, @odd_offsets = normalize_offsets( get_values( directions ))
@even_mask = mask_for_offsets( @even_offsets)
@odd_mask = mask_for_offsets( @odd_offsets)
@start_masks = Array.new(60)
# create the rotational masks by placing the base mask at the location and seeing if
# 1) it overlaps the boundaries and 2) it produces a prunable board. if either of these
# is true the piece cannot be placed
0.upto(59) do | offset |
mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset)
if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then
imask = compute_required( mask, offset)
@start_masks[offset] = [ mask, imask, imask | mask ]
else
@start_masks[offset] = false
end
end
end
def compute_required( mask, offset )
board = blank_board
0.upto(offset) { | i | board |= 1 << i }
board |= mask
return 0 if (!prunable(board | mask, offset))
board = flood_fill(board,58)
count = 0
imask = 0
0.upto(59) do | i |
if (board[i] == 0) then
imask |= (1 << i)
count += 1
end
end
(count > 0 && count < 5) ? imask : 0
end
def flood_fill( board, location)
return board if (board[location] == 1)
board |= 1 << location
row, col = location.divmod(6)
board = flood_fill( board, location - 1) if (col > 0)
board = flood_fill( board, location + 1) if (col < 4)
if (row % 2 == 0) then
board = flood_fill( board, location - 7) if (col > 0 && row > 0)
board = flood_fill( board, location - 6) if (row > 0)
board = flood_fill( board, location + 6) if (row < 9)
board = flood_fill( board, location + 5) if (col > 0 && row < 9)
else
board = flood_fill( board, location - 5) if (col < 4 && row > 0)
board = flood_fill( board, location - 6) if (row > 0)
board = flood_fill( board, location + 6) if (row < 9)
board = flood_fill( board, location + 7) if (col < 4 && row < 9)
end
board
end
# given a location, produces a list of relative locations covered by the piece at this rotation
def offsets( location)
if is_even( location) then
@even_offsets.collect { | value | value + location }
else
@odd_offsets.collect { | value | value + location }
end
end
# returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows)
# this is hard to explain. imagine we have this partial board:
# 0 0 0 0 0 x [positions 0-5]
# 0 0 1 1 0 x [positions 6-11]
# 0 0 1 0 0 x [positions 12-17]
# 0 1 0 0 0 x [positions 18-23]
# 0 1 0 0 0 x [positions 24-29]
# 0 0 0 0 0 x [positions 30-35]
# ...
# The top-left of the piece is at position 8, the
# board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that
# sorted order. Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained
# by subtracting 8 from everything. Now imagine the piece shifted up and to the right so it's on an even row:
# 0 0 0 1 1 x [positions 0-5]
# 0 0 1 0 0 x [positions 6-11]
# 0 0 1 0 0 x [positions 12-17]
# 0 1 0 0 0 x [positions 18-23]
# 0 0 0 0 0 x [positions 24-29]
# 0 0 0 0 0 x [positions 30-35]
# ...
# Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the
# offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what
# this function would return
def normalize_offsets( values)
min = values.min
even_min = is_even(min)
other_min = even_min ? min + 6 : min + 7
other_values = values.collect do | value |
if is_even(value) then
value + 6 - other_min
else
value + 7 - other_min
end
end
values.collect! { | value | value - min }
if even_min then
[values, other_values]
else
[other_values, values]
end
end
# produce a bitmask representation of an array of offset locations
def mask_for_offsets( offsets )
mask = 0
offsets.each { | value | mask = mask + ( 1 << value ) }
mask
end
# finds a "safe" position that a position as described by a list of directions can be placed
# without falling off any edge of the board. the values returned a location to place the first piece
# at so it will fit after making the described moves
def start_adjust( directions )
south = east = 0;
directions.each do | direction |
east += 1 if ( direction == :sw || direction == :nw || direction == :west )
south += 1 if ( direction == :nw || direction == :ne )
end
south * 6 + east
end
# given a set of directions places the piece (as defined by a set of directions) on the board at
# a location that will not take it off the edge
def get_values ( directions )
start = start_adjust(directions)
values = [ start ]
directions.each do | direction |
if (start % 12 >= 6) then
start += @@rotation_odd_adder[direction]
else
start += @@rotation_even_adder[direction]
end
values += [ start ]
end
# some moves take you back to an existing location, we'll strip duplicates
values.uniq
end
end
# describes a piece and caches information about its rotations to as to be efficient for iteration
# ATTRIBUTES:
# rotations -- all the rotations of the piece
# type -- a numeic "name" of the piece
# masks -- an array by location of all legal rotational masks (a n inner array) for that location
# placed -- the mask that this piece was last placed at (not a location, but the actual mask used)
class Piece
attr_reader :rotations, :type, :masks
attr_accessor :placed
# transform hashes that change one direction into another when you either flip or rotate a set of directions
@@flip_converter = { :west => :west, :east => :east, :nw => :sw, :ne => :se, :sw => :nw, :se => :ne }
@@rotate_converter = { :west => :nw, :east => :se, :nw => :ne, :ne => :east, :sw => :west, :se => :sw }
def initialize( directions, type )
@type = type
@rotations = Array.new();
@map = {}
generate_rotations( directions )
directions.collect! { | value | @@flip_converter[value] }
generate_rotations( directions )
# creates the masks AND a map that returns [location, rotation] for any given mask
# this is used when a board is found and we want to draw it, otherwise the map is unused
@masks = Array.new();
0.upto(59) do | i |
even = true
@masks[i] = @rotations.collect do | rotation |
mask = rotation.start_masks[i]
@map[mask[0]] = [ i, rotation ] if (mask)
mask || nil
end
@masks[i].compact!
end
end
# rotates a set of directions through all six angles and adds a Rotation to the list for each one
def generate_rotations( directions )
6.times do
rotations.push( Rotation.new(directions))
directions.collect! { | value | @@rotate_converter[value] }
end
end
# given a board string, adds this piece to the board at whatever location/rotation
# important: the outbound board string is 5 wide, the normal location notation is six wide (padded)
def fill_string( board_string)
location, rotation = @map[@placed]
rotation.offsets(location).each do | offset |
row, col = offset.divmod(6)
board_string[ row*5 + col, 1 ] = @type.to_s
end
end
end
# a blank bit board having this form:
#
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 0 0 0 0 0 1
# 1 1 1 1 1 1
#
# where left lest significant bit is the top left and the most significant is the lower right
# the actual board only consists of the 0 places, the 1 places are blockers to keep things from running
# off the edges or bottom
def blank_board
0b111111100000100000100000100000100000100000100000100000100000100000
end
def full_board
0b111111111111111111111111111111111111111111111111111111111111111111
end
# determines if a location (bit position) is in an even row
def is_even( location)
(location % 12) < 6
end
# support function that create three utility maps:
# $converter -- for each row an array that maps a five bit row (via array mapping)
# to the a a five bit representation of the bits below it
# $bit_count -- maps a five bit row (via array mapping) to the number of 1s in the row
# @@new_regions -- maps a five bit row (via array mapping) to an array of "region" arrays
# a region array has three values the first is a mask of bits in the region,
# the second is the count of those bits and the third is identical to the first
# examples:
# 0b10010 => [ 0b01100, 2, 0b01100 ], [ 0b00001, 1, 0b00001]
# 0b01010 => [ 0b10000, 1, 0b10000 ], [ 0b00100, 1, 0b00100 ], [ 0b00001, 1, 0b00001]
# 0b10001 => [ 0b01110, 3, 0b01110 ]
def create_collector_support
odd_map = [0b11, 0b110, 0b1100, 0b11000, 0b10000]
even_map = [0b1, 0b11, 0b110, 0b1100, 0b11000]
all_odds = Array.new(0b100000)
all_evens = Array.new(0b100000)
bit_counts = Array.new(0b100000)
new_regions = Array.new(0b100000)
0.upto(0b11111) do | i |
bit_count = odd = even = 0
0.upto(4) do | bit |
if (i[bit] == 1) then
bit_count += 1
odd |= odd_map[bit]
even |= even_map[bit]
end
end
all_odds[i] = odd
all_evens[i] = even
bit_counts[i] = bit_count
new_regions[i] = create_regions( i)
end
$converter = []
10.times { | row | $converter.push((row % 2 == 0) ? all_evens : all_odds) }
$bit_counts = bit_counts
$regions = new_regions.collect { | set | set.collect { | value | [ value, bit_counts[value], value] } }
end
# determines if a board is punable, meaning that there is no possibility that it
# can be filled up with pieces. A board is prunable if there is a grouping of unfilled spaces
# that are not a multiple of five. The following board is an example of a prunable board:
# 0 0 1 0 0
# 0 1 0 0 0
# 1 1 0 0 0
# 0 1 0 0 0
# 0 0 0 0 0
# ...
#
# This board is prunable because the top left corner is only 3 bits in area, no piece will ever fit it
# parameters:
# board -- an initial bit board (6 bit padded rows, see blank_board for format)
# location -- starting location, everything above and to the left is already full
# slotting -- set to true only when testing initial pieces, when filling normally
# additional assumptions are possible
#
# Algorithm:
# The algorithm starts at the top row (as determined by location) and iterates a row at a time
# maintainng counts of active open areas (kept in the collector array) each collector contains
# three values at the start of an iteration:
# 0: mask of bits that would be adjacent to the collector in this row
# 1: the number of bits collected so far
# 2: a scratch space starting as zero, but used during the computation to represent
# the empty bits in the new row that are adjacent (position 0)
# The exact procedure is described in-code
def prunable( board, location, slotting = false)
collectors = []
# loop across the rows
(location / 6).to_i.upto(9) do | row_on |
# obtain a set of regions representing the bits of the current row.
regions = $regions[(board >> (row_on * 6)) & 0b11111]
converter = $converter[row_on]
# track the number of collectors at the start of the cycle so that
# we don't compute against newly created collectors, only existing collectors
initial_collector_count = collectors.length
# loop against the regions. For each region of the row
# we will see if it connects to one or more existing collectors.
# if it connects to 1 collector, the bits from the region are added to the
# bits of the collector and the mask is placed in collector[2]
# If the region overlaps more than one collector then all the collectors
# it overlaps with are merged into the first one (the others are set to nil in the array)
# if NO collectors are found then the region is copied as a new collector
regions.each do | region |
collector_found = nil
region_mask = region[2]
initial_collector_count.times do | collector_num |
collector = collectors[collector_num]
if (collector) then
collector_mask = collector[0]
if (collector_mask & region_mask != 0) then
if (collector_found) then
collector_found[0] |= collector_mask
collector_found[1] += collector[1]
collector_found[2] |= collector[2]
collectors[collector_num] = nil
else
collector_found = collector
collector[1] += region[1]
collector[2] |= region_mask
end
end
end
end
if (collector_found == nil) then
collectors.push(Array.new(region))
end
end
# check the existing collectors, if any collector overlapped no bits in the region its [2] value will
# be zero. The size of any such reaason is tested if it is not a multiple of five true is returned since
# the board is prunable. if it is a multiple of five it is removed.
# Collector that are still active have a new adjacent value [0] set based n the matched bits
# and have [2] cleared out for the next cycle.
collectors.length.times do | collector_num |
collector = collectors[collector_num]
if (collector) then
if (collector[2] == 0) then
return true if (collector[1] % 5 != 0)
collectors[collector_num] = nil
else
# if a collector matches all bits in the row then we can return unprunable early for the
# following reasons:
# 1) there can be no more unavailable bits bince we fill from the top left downward
# 2) all previous regions have been closed or joined so only this region can fail
# 3) this region must be good since there can never be only 1 region that is nuot
# a multiple of five
# this rule only applies when filling normally, so we ignore the rule if we are "slotting"
# in pieces to see what configurations work for them (the only other time this algorithm is used).
return false if (collector[2] == 0b11111 && !slotting)
collector[0] = converter[collector[2]]
collector[2] = 0
end
end
end
# get rid of all the empty converters for the next round
collectors.compact!
end
return false if (collectors.length <= 1) # 1 collector or less and the region is fine
collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size
end
# creates a region given a row mask. see prunable for what a "region" is
def create_regions( value )
regions = []
cur_region = 0
5.times do | bit |
if (value[bit] == 0) then
cur_region |= 1 << bit
else
if (cur_region != 0 ) then
regions.push( cur_region)
cur_region = 0;
end
end
end
regions.push(cur_region) if (cur_region != 0)
regions
end
# find up to the counted number of solutions (or all solutions) and prints the final result
def find_all
find_top( 1)
find_top( 0)
print_results
end
# show the board
def print_results
print "#{@boards_found} solutions found\n\n"
print_full_board( @min_board)
print "\n"
print_full_board( @max_board)
print "\n"
end
# finds solutions. This special version of the main function is only used for the top level
# the reason for it is basically to force a particular ordering on how the rotations are tested for
# the first piece. It is called twice, first looking for placements of the odd rotations and then
# looking for placements of the even locations.
#
# WHY?
# Since any found solution has an inverse we want to maximize finding solutions that are not already found
# as an inverse. The inverse will ALWAYS be 3 one of the piece configurations that is exactly 3 rotations away
# (an odd number). Checking even vs odd then produces a higher probability of finding more pieces earlier
# in the cycle. We still need to keep checking all the permutations, but our probability of finding one will
# diminsh over time. Since we are TOLD how many to search for this lets us exit before checking all pieces
# this bennifit is very great when seeking small numbers of solutions and is 0 when looking for more than the
# maximum number
def find_top( rotation_skip)
board = blank_board
(@pieces.length-1).times do
piece = @pieces.shift
piece.masks[0].each do | mask, imask, cmask |
if ((rotation_skip += 1) % 2 == 0) then
piece.placed = mask
find( 1, 1, board | mask)
end
end
@pieces.push(piece)
end
piece = @pieces.shift
@pieces.push(piece)
end
# the normail find routine, iterates through the available pieces, checks all rotations at the current location
# and adds any boards found. depth is acheived via recursion. the overall approach is described
# here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/
# parameters:
# start_location -- where to start looking for place for the next piece at
# placed -- number of pieces placed
# board -- current state of the board
#
# see in-code comments
def find( start_location, placed, board)
# find the next location to place a piece by looking for an empty bit
while board[start_location] == 1
start_location += 1
end
@pieces.length.times do
piece = @pieces.shift
piece.masks[start_location].each do | mask, imask, cmask |
if ( board & cmask == imask) then
piece.placed = mask
if (placed == 9) then
add_board
else
find( start_location + 1, placed + 1, board | mask)
end
end
end
@pieces.push(piece)
end
end
# print the board
def print_full_board( board_string)
10.times do | row |
print " " if (row % 2 == 1)
5.times do | col |
print "#{board_string[row*5 + col,1]} "
end
print "\n"
end
end
# when a board is found we "draw it" into a string and then flip that string, adding both to
# the list (hash) of solutions if they are unique.
def add_board
board_string = "99999999999999999999999999999999999999999999999999"
@all_pieces.each { | piece | piece.fill_string( board_string ) }
save( board_string)
save( board_string.reverse)
end
# adds a board string to the list (if new) and updates the current best/worst board
def save( board_string)
if (@all_boards[board_string] == nil) then
@min_board = board_string if (board_string < @min_board)
@max_board = board_string if (board_string > @max_board)
@all_boards.store(board_string,true)
@boards_found += 1
# the exit motif is a time saver. Ideally the function should return, but those tests
# take noticeable time (performance).
if (@boards_found == @stop_count) then
print_results
exit(0)
end
end
end
##
## MAIN BODY :)
##
create_collector_support
@pieces = [
Piece.new( [ :nw, :ne, :east, :east ], 2),
Piece.new( [ :ne, :se, :east, :ne ], 7),
Piece.new( [ :ne, :east, :ne, :nw ], 1),
Piece.new( [ :east, :sw, :sw, :se ], 6),
Piece.new( [ :east, :ne, :se, :ne ], 5),
Piece.new( [ :east, :east, :east, :se ], 0),
Piece.new( [ :ne, :nw, :se, :east, :se ], 4),
Piece.new( [ :se, :se, :se, :west ], 9),
Piece.new( [ :se, :se, :east, :se ], 8),
Piece.new( [ :east, :east, :sw, :se ], 3)
];
@all_pieces = Array.new( @pieces)
@min_board = "99999999999999999999999999999999999999999999999999"
@max_board = "00000000000000000000000000000000000000000000000000"
@stop_count = ARGV[0].to_i || 2089
@all_boards = {}
@boards_found = 0
find_all ######## DO IT!!!
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.346106839
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.302482741
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.312275702
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.315781148
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.312463979
built-ruby 2.27316419
built-ruby 2.280041399
built-ruby 2.277637662
built-ruby 2.272801355
built-ruby 2.291809088
-----------------------------------------------------------
so_nbody
# The Computer Language Shootout
# http://shootout.alioth.debian.org
#
# Optimized for Ruby by Jesse Millikan
# From version ported by Michael Neumann from the C gcc version,
# which was written by Christoph Bauer.
SOLAR_MASS = 4 * Math::PI**2
DAYS_PER_YEAR = 365.24
def _puts *args
end
class Planet
attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass
def initialize(x, y, z, vx, vy, vz, mass)
@x, @y, @z = x, y, z
@vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR
@mass = mass * SOLAR_MASS
end
def move_from_i(bodies, nbodies, dt, i)
while i < nbodies
b2 = bodies[i]
dx = @x - b2.x
dy = @y - b2.y
dz = @z - b2.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
mag = dt / (distance * distance * distance)
b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag
@vx -= dx * b2_mass_mag
@vy -= dy * b2_mass_mag
@vz -= dz * b2_mass_mag
b2.vx += dx * b_mass_mag
b2.vy += dy * b_mass_mag
b2.vz += dz * b_mass_mag
i += 1
end
@x += dt * @vx
@y += dt * @vy
@z += dt * @vz
end
end
def energy(bodies)
e = 0.0
nbodies = bodies.size
for i in 0 ... nbodies
b = bodies[i]
e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz)
for j in (i + 1) ... nbodies
b2 = bodies[j]
dx = b.x - b2.x
dy = b.y - b2.y
dz = b.z - b2.z
distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
e -= (b.mass * b2.mass) / distance
end
end
e
end
def offset_momentum(bodies)
px, py, pz = 0.0, 0.0, 0.0
for b in bodies
m = b.mass
px += b.vx * m
py += b.vy * m
pz += b.vz * m
end
b = bodies[0]
b.vx = - px / SOLAR_MASS
b.vy = - py / SOLAR_MASS
b.vz = - pz / SOLAR_MASS
end
BODIES = [
# sun
Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),
# jupiter
Planet.new(
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-01,
1.66007664274403694e-03,
7.69901118419740425e-03,
-6.90460016972063023e-05,
9.54791938424326609e-04),
# saturn
Planet.new(
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
-2.76742510726862411e-03,
4.99852801234917238e-03,
2.30417297573763929e-05,
2.85885980666130812e-04),
# uranus
Planet.new(
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
2.96460137564761618e-03,
2.37847173959480950e-03,
-2.96589568540237556e-05,
4.36624404335156298e-05),
# neptune
Planet.new(
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
2.68067772490389322e-03,
1.62824170038242295e-03,
-9.51592254519715870e-05,
5.15138902046611451e-05)
]
init = 200_000 # ARGV[0]
n = Integer(init)
offset_momentum(BODIES)
puts "%.9f" % energy(BODIES)
nbodies = BODIES.size
dt = 0.01
n.times do
i = 0
while i < nbodies
b = BODIES[i]
b.move_from_i(BODIES, nbodies, dt, i + 1)
i += 1
end
end
puts "%.9f" % energy(BODIES)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.036331877
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.03450402
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.037135918
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.033731398
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.032142335
built-ruby 1.042902988
built-ruby 1.060518119
built-ruby 1.055467436
built-ruby 1.080290969
built-ruby 1.049325602
-----------------------------------------------------------
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
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.882220188
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.849223525
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.857062062
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.857260863
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.858790016
built-ruby 0.871607472
built-ruby 0.857895009
built-ruby 0.860841215
built-ruby 0.859971415
built-ruby 0.859932085
-----------------------------------------------------------
so_nsieve
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Glenn Parker, March 2005
# modified by Evan Phoenix, Sept 2006
def sieve(m)
flags = Flags.dup[0,m]
count = 0
pmax = m - 1
p = 2
while p <= pmax
unless flags[p].zero?
count += 1
mult = p
while mult <= pmax
flags[mult] = 0
mult += p
end
end
p += 1
end
count
end
n = 9 # (ARGV[0] || 2).to_i
Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*")
n.downto(n-2) do |exponent|
break if exponent < 0
m = (1 << exponent) * 10_000
# m = (2 ** exponent) * 10_000
count = sieve(m)
printf "Primes up to %8d %8d\n", m, count
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.27335187
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.272955539
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.273710155
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.273389171
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.274520971
built-ruby 1.30402645
built-ruby 1.31789997
built-ruby 1.319956777
built-ruby 1.315133333
built-ruby 1.309283654
-----------------------------------------------------------
so_nsieve_bits
#!/usr/bin/ruby
#coding: us-ascii
#
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# nsieve-bits in Ruby
# Contributed by Glenn Parker, March 2005
CharExponent = 3
BitsPerChar = 1 << CharExponent
LowMask = BitsPerChar - 1
def sieve(m)
items = "\xFF" * ((m / BitsPerChar) + 1)
masks = ""
BitsPerChar.times do |b|
masks << (1 << b).chr
end
count = 0
pmax = m - 1
2.step(pmax, 1) do |p|
if items[p >> CharExponent][p & LowMask] == 1
count += 1
p.step(pmax, p) do |mult|
a = mult >> CharExponent
b = mult & LowMask
items[a] -= masks[b] if items[a][b] != 0
end
end
end
count
end
n = 9 # (ARGV[0] || 2).to_i
n.step(n - 2, -1) do |exponent|
break if exponent < 0
m = 2 ** exponent * 10_000
count = sieve(m)
printf "Primes up to %8d %8d\n", m, count
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.803575617
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.78059098
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.754877029
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.755289816
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.753002675
built-ruby 1.749755645
built-ruby 1.749885427
built-ruby 1.749716495
built-ruby 1.75086394
built-ruby 1.748653236
-----------------------------------------------------------
so_object
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Aristarkh Zagorodnikov
class Toggle
def initialize(start_state)
@bool = start_state
end
def value
@bool
end
def activate
@bool = !@bool
self
end
end
class NthToggle < Toggle
def initialize(start_state, max_counter)
super start_state
@count_max = max_counter
@counter = 0
end
def activate
@counter += 1
if @counter >= @count_max
@bool = !@bool
@counter = 0
end
self
end
end
n = 1500000 # (ARGV.shift || 1).to_i
toggle = Toggle.new 1
5.times do
toggle.activate.value ? 'true' : 'false'
end
n.times do
toggle = Toggle.new 1
end
ntoggle = NthToggle.new 1, 3
8.times do
ntoggle.activate.value ? 'true' : 'false'
end
n.times do
ntoggle = NthToggle.new 1, 3
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.541664612
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.540661928
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.540679187
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.540702256
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.541101442
built-ruby 0.539835463
built-ruby 0.539820934
built-ruby 0.543497667
built-ruby 0.540757656
built-ruby 0.539715016
-----------------------------------------------------------
so_partial_sums
n = 2_500_000 # (ARGV.shift || 1).to_i
alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0
1.upto(n) do |d|
d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d)
s0 += (2.0 / 3.0) ** (d - 1.0)
s1 += 1.0 / Math.sqrt(d)
s2 += 1.0 / (d * (d + 1.0))
s3 += 1.0 / (d3 * ds * ds)
s4 += 1.0 / (d3 * dc * dc)
s5 += 1.0 / d
s6 += 1.0 / d2
s7 += alt / d
s8 += alt / (2.0 * d - 1.0)
alt = -alt
end
if false
printf("%.9f\t(2/3)^k\n", s0)
printf("%.9f\tk^-0.5\n", s1)
printf("%.9f\t1/k(k+1)\n", s2)
printf("%.9f\tFlint Hills\n", s3)
printf("%.9f\tCookson Hills\n", s4)
printf("%.9f\tHarmonic\n", s5)
printf("%.9f\tRiemann Zeta\n", s6)
printf("%.9f\tAlternating Harmonic\n", s7)
printf("%.9f\tGregory\n", s8)
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.539232053
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.558112249
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.591086458
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.538470688
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.553809763
built-ruby 1.598119629
built-ruby 1.592759762
built-ruby 1.594379359
built-ruby 1.621717324
built-ruby 1.613413621
-----------------------------------------------------------
so_pidigits
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Gabriele Renzi
class PiDigitSpigot
def initialize()
@z = Transformation.new 1,0,0,1
@x = Transformation.new 0,0,0,0
@inverse = Transformation.new 0,0,0,0
end
def next!
@y = @z.extract(3)
if safe? @y
@z = produce(@y)
@y
else
@z = consume @x.next!()
next!()
end
end
def safe?(digit)
digit == @z.extract(4)
end
def produce(i)
@inverse.qrst(10,-10*i,0,1).compose(@z)
end
def consume(a)
@z.compose(a)
end
end
class Transformation
attr_reader :q, :r, :s, :t
def initialize (q, r, s, t)
@q,@r,@s,@t,@k = q,r,s,t,0
end
def next!()
@q = @k = @k + 1
@r = 4 * @k + 2
@s = 0
@t = 2 * @k + 1
self
end
def extract(j)
(@q * j + @r) / (@s * j + @t)
end
def compose(a)
self.class.new( @q * a.q,
@q * a.r + r * a.t,
@s * a.q + t * a.s,
@s * a.r + t * a.t
)
end
def qrst *args
initialize *args
self
end
end
WIDTH = 10
n = 2_500 # Integer(ARGV[0])
j = 0
digits = PiDigitSpigot.new
while n > 0
if n >= WIDTH
WIDTH.times {print digits.next!}
j += WIDTH
else
n.times {print digits.next!}
(WIDTH-n).times {print " "}
j += n
end
puts "\t:"+j.to_s
n -= WIDTH
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.813485789
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.829335505
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.817674143
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.817558843
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.82188224
built-ruby 1.085473109
built-ruby 1.066623561
built-ruby 1.064218692
built-ruby 1.063929873
built-ruby 1.071403967
-----------------------------------------------------------
so_random
# 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 = 3_000_000
i = 0
while i/
if seq.length != 0
revcomp(seq.join)
seq=Array.new
end
puts $_
else
$_.sub(/\n/,'')
seq.push $_
end
end
revcomp(seq.join)
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.937451324
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.94408458
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.940329208
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.947023647
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.937593473
built-ruby 0.816277826
built-ruby 0.81261503
built-ruby 0.809923319
built-ruby 0.812248045
built-ruby 0.814704589
-----------------------------------------------------------
so_sieve
# from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
num = 500
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
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.404147041
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.40049323
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.40037814
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.400512384
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.400431593
built-ruby 0.401952723
built-ruby 0.401643751
built-ruby 0.40376014
built-ruby 0.402179668
built-ruby 0.407343008
-----------------------------------------------------------
so_spectralnorm
# The Computer Language Shootout
# http://shootout.alioth.debian.org/
# Contributed by Sokolov Yura
def eval_A(i,j)
return 1.0/((i+j)*(i+j+1)/2+i+1)
end
def eval_A_times_u(u)
v, i = nil, nil
(0..u.length-1).collect { |i|
v = 0
for j in 0..u.length-1
v += eval_A(i,j)*u[j]
end
v
}
end
def eval_At_times_u(u)
v, i = nil, nil
(0..u.length-1).collect{|i|
v = 0
for j in 0..u.length-1
v += eval_A(j,i)*u[j]
end
v
}
end
def eval_AtA_times_u(u)
return eval_At_times_u(eval_A_times_u(u))
end
n = 500 # ARGV[0].to_i
u=[1]*n
for i in 1..10
v=eval_AtA_times_u(u)
u=eval_AtA_times_u(v)
end
vBv=0
vv=0
for i in 0..n-1
vBv += u[i]*v[i]
vv += v[i]*v[i]
end
str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n"
# print str
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.635675123
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.614573694
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.609882045
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.64174529
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.625690595
built-ruby 1.656506857
built-ruby 1.59351547
built-ruby 1.603921442
built-ruby 1.597642457
built-ruby 1.592886294
-----------------------------------------------------------
vm1_attr_ivar
class C
attr_reader :a, :b
def initialize
@a = nil
@b = nil
end
end
obj = C.new
i = 0
while i<30_000_000 # while loop 1
i += 1
j = obj.a
k = obj.b
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.951868305
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.95023066
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.970477475
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.946625349
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.964721446
built-ruby 0.94802164
built-ruby 0.95237309
built-ruby 0.950580883
built-ruby 0.969576818
built-ruby 0.948151632
-----------------------------------------------------------
vm1_attr_ivar_set
class C
attr_accessor :a, :b
def initialize
@a = nil
@b = nil
end
end
obj = C.new
i = 0
while i<30_000_000 # while loop 1
i += 1
obj.a = 1
obj.b = 2
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.238630195
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.237502189
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.239040476
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.23829435
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.217977314
built-ruby 1.234690797
built-ruby 1.235451503
built-ruby 1.234493855
built-ruby 1.234627671
built-ruby 1.233720676
-----------------------------------------------------------
vm1_block
def m
yield
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m{
}
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.763905489
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.786817721
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.782670748
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.771454803
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.773058586
built-ruby 1.750985576
built-ruby 1.753108473
built-ruby 1.750762298
built-ruby 1.750935942
built-ruby 1.753624397
-----------------------------------------------------------
vm1_const
Const = 1
i = 0
while i<30_000_000 # while loop 1
i += 1
j = Const
k = Const
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.649568867
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.649199762
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.644091163
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.644541068
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.649169237
built-ruby 0.644373485
built-ruby 0.644477453
built-ruby 0.644335097
built-ruby 0.644398045
built-ruby 0.644356396
-----------------------------------------------------------
vm1_ensure
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
begin
begin
ensure
end
ensure
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.444851026
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.444561736
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.444605464
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.444587579
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.444620947
built-ruby 0.4445253
built-ruby 0.44463885
built-ruby 0.444650574
built-ruby 0.444694544
built-ruby 0.444617373
-----------------------------------------------------------
vm1_float_simple
i = 0.0; f = 0.0
while i<30_000_000
i += 1
f += 0.1; f -= 0.1
f += 0.1; f -= 0.1
f += 0.1; f -= 0.1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.933607406
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.91488297
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 4.008902837
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.815027657
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 3.896616952
built-ruby 3.758851654
built-ruby 3.776113393
built-ruby 3.762754535
built-ruby 3.74562069
built-ruby 3.764975398
-----------------------------------------------------------
vm1_gc_short_lived
i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.077427713
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.043701996
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.044109641
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.045306945
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.222482311
built-ruby 8.193261899
built-ruby 8.061998555
built-ruby 8.023748952
built-ruby 8.032294478
built-ruby 8.022910701
-----------------------------------------------------------
vm1_gc_short_with_complex_long
def nested_hash h, n
if n == 0
''
else
10.times{
h[Object.new] = nested_hash(h, n-1)
}
end
end
long_lived = Hash.new
nested_hash long_lived, 6
GC.start
GC.start
i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 9.196036308
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 9.257389306
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 9.282357932
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 9.324814123
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 9.2288147
built-ruby 8.994394248
built-ruby 8.951029129
built-ruby 8.946878015
built-ruby 8.961432309
built-ruby 8.961894858
-----------------------------------------------------------
vm1_gc_short_with_long
long_lived = Array.new(1_000_000){|i| "#{i}"}
GC.start
GC.start
i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.871914959
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.68677741
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.831344222
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.66539906
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.676532495
built-ruby 8.588345151
built-ruby 8.555826207
built-ruby 8.560542464
built-ruby 8.741063773
built-ruby 8.599878854
-----------------------------------------------------------
vm1_gc_short_with_symbol
# make many symbols
50_000.times{|i| sym = "sym#{i}".to_sym}
GC.start
GC.start
i = 0
while i<30_000_000 # while loop 1
a = '' # short-lived String
b = ''
c = ''
d = ''
e = ''
f = ''
i+=1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.072840529
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.078566206
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.067642127
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.054434034
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 8.058901444
built-ruby 7.980526835
built-ruby 8.028023067
built-ruby 8.119479259
built-ruby 7.987226733
built-ruby 7.947796678
-----------------------------------------------------------
vm1_gc_wb_ary
long_lived = []
GC.start
GC.start
i = 0
short_lived = ''
while i<30_000_000 # while loop 1
long_lived[0] = short_lived # write barrier
i+=1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.880185883
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.880019599
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.879911644
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.879817047
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.879823921
built-ruby 0.881004716
built-ruby 0.881050595
built-ruby 0.88095787
built-ruby 0.881101386
built-ruby 0.882378443
-----------------------------------------------------------
vm1_gc_wb_obj
class C
attr_accessor :foo
end
long_lived = C.new
GC.start
GC.start
i = 0
short_lived = ''
while i<30_000_000 # while loop 1
long_lived.foo = short_lived # write barrier
i+=1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.930667164
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.932964691
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.931206513
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.928748837
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.930189225
built-ruby 0.934733886
built-ruby 0.939294385
built-ruby 0.942562635
built-ruby 0.933507581
built-ruby 0.929236124
-----------------------------------------------------------
vm1_ivar
@a = 1
i = 0
while i<30_000_000 # while loop 1
i += 1
j = @a
k = @a
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.650069262
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.649779509
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.649890702
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.649858337
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.648816706
built-ruby 0.644103214
built-ruby 0.644142191
built-ruby 0.644011547
built-ruby 0.644094194
built-ruby 0.644631703
-----------------------------------------------------------
vm1_ivar_set
i = 0
while i<30_000_000 # while loop 1
i += 1
@a = 1
@b = 2
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.738896166
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.738960198
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.738772241
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.738840464
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.737033908
built-ruby 0.740232588
built-ruby 0.740150915
built-ruby 0.779650724
built-ruby 0.740057328
built-ruby 0.736520145
-----------------------------------------------------------
vm1_length
a = 'abc'
b = [1, 2, 3]
i = 0
while i<30_000_000 # while loop 1
i += 1
a.length
b.length
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.882390699
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.881469978
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.942197138
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.878916531
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.879024932
built-ruby 0.875905951
built-ruby 0.873625385
built-ruby 0.870927387
built-ruby 0.875616463
built-ruby 0.873551123
-----------------------------------------------------------
vm1_lvar_init
def m v
unless v
# unreachable code
v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = v10 =
v11 = v12 = v13 = v14 = v15 = v16 = v17 = v18 = v19 = v20 =
v21 = v22 = v23 = v24 = v25 = v26 = v27 = v28 = v29 = v30 =
v31 = v32 = v33 = v34 = v35 = v36 = v37 = v38 = v39 = v40 =
v41 = v42 = v43 = v44 = v45 = v46 = v47 = v48 = v49 = v50 = 1
end
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m i
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.497934382
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.512122084
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.53804804
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.530964325
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.531398691
built-ruby 1.546189213
built-ruby 1.53568576
built-ruby 1.540784208
built-ruby 1.51406354
built-ruby 1.496396261
-----------------------------------------------------------
vm1_lvar_set
i = 0
while i<30_000_000 # while loop 1
i += 1
a = b = c = d = e = f = g = h = j = k = l = m = n = o = p = q = r = 1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.17797115
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.177510763
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.178298082
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.17757319
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.177650919
built-ruby 2.178623139
built-ruby 2.179326325
built-ruby 2.178282463
built-ruby 2.178480174
built-ruby 2.178494715
-----------------------------------------------------------
vm1_neq
i = 0
obj1 = Object.new
obj2 = Object.new
while i<30_000_000 # while loop 1
i += 1
obj1 != obj2
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.831978424
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.832230081
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.83536766
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.831601037
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.831828493
built-ruby 0.833231359
built-ruby 0.8324993
built-ruby 0.836305229
built-ruby 0.841101606
built-ruby 0.834732883
-----------------------------------------------------------
vm1_not
i = 0
obj = Object.new
while i<30_000_000 # while loop 1
i += 1
!obj
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.652520991
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.652480776
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.652535061
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.652416971
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.652388845
built-ruby 0.653148607
built-ruby 0.652997286
built-ruby 0.653052609
built-ruby 0.653150994
built-ruby 0.653096643
-----------------------------------------------------------
vm1_rescue
i = 0
while i<30_000_000 # while loop 1
i += 1
begin
rescue
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.540021841
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.539767095
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.539696573
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.539123287
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.541619732
built-ruby 0.539957908
built-ruby 0.539664998
built-ruby 0.539515942
built-ruby 0.539197604
built-ruby 0.539503279
-----------------------------------------------------------
vm1_simplereturn
def m
return 1
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.075057283
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.07538519
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.084796184
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.076065425
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.13635983
built-ruby 1.074568131
built-ruby 1.074615265
built-ruby 1.07455247
built-ruby 1.074480213
built-ruby 1.212193749
-----------------------------------------------------------
vm1_swap
a = 1
b = 2
i = 0
while i<30_000_000 # while loop 1
i += 1
a, b = b, a
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.643027587
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.642832452
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.642861701
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.645778263
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.643713955
built-ruby 0.71163427
built-ruby 0.755884297
built-ruby 0.69795838
built-ruby 0.672138505
built-ruby 0.655396402
-----------------------------------------------------------
vm1_yield
def m
i = 0
while i<30_000_000 # while loop 1
i += 1
yield
end
end
m{}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.037069496
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.068960711
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.063999659
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.092818182
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.025343621
built-ruby 1.010905961
built-ruby 1.016305915
built-ruby 1.010436998
built-ruby 1.010258107
built-ruby 1.010401301
-----------------------------------------------------------
vm2_array
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
a = [1,2,3,4,5,6,7,8,9,10]
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.65479647
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.660175212
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.656918957
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.653186881
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.656472655
built-ruby 0.751918266
built-ruby 0.745919544
built-ruby 0.746639011
built-ruby 0.752509551
built-ruby 0.759527069
-----------------------------------------------------------
vm2_bigarray
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
a = [
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
1,2,3,4,5,6,7,8,9,10,
]
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 6.186458737
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 6.331982299
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 6.126739506
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 6.199049029
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 6.185787482
built-ruby 13.89186711
built-ruby 14.300612041
built-ruby 13.908187246
built-ruby 13.942563665
built-ruby 13.890603208
-----------------------------------------------------------
vm2_bighash
i = 0
while i<60_000 # benchmark loop 2
i += 1
a = {0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 19=>19, 20=>20, 21=>21, 22=>22, 23=>23, 24=>24, 25=>25, 26=>26, 27=>27, 28=>28, 29=>29, 30=>30, 31=>31, 32=>32, 33=>33, 34=>34, 35=>35, 36=>36, 37=>37, 38=>38, 39=>39, 40=>40, 41=>41, 42=>42, 43=>43, 44=>44, 45=>45, 46=>46, 47=>47, 48=>48, 49=>49, 50=>50, 51=>51, 52=>52, 53=>53, 54=>54, 55=>55, 56=>56, 57=>57, 58=>58, 59=>59, 60=>60, 61=>61, 62=>62, 63=>63, 64=>64, 65=>65, 66=>66, 67=>67, 68=>68, 69=>69, 70=>70, 71=>71, 72=>72, 73=>73, 74=>74, 75=>75, 76=>76, 77=>77, 78=>78, 79=>79, 80=>80, 81=>81, 82=>82, 83=>83, 84=>84, 85=>85, 86=>86, 87=>87, 88=>88, 89=>89, 90=>90, 91=>91, 92=>92, 93=>93, 94=>94, 95=>95, 96=>96, 97=>97, 98=>98, 99=>99, 100=>100, 101=>101, 102=>102, 103=>103, 104=>104, 105=>105, 106=>106, 107=>107, 108=>108, 109=>109, 110=>110, 111=>111, 112=>112, 113=>113, 114=>114, 115=>115, 116=>116, 117=>117, 118=>118, 119=>119, 120=>120, 121=>121, 122=>122, 123=>123, 124=>124, 125=>125, 126=>126, 127=>127, 128=>128, 129=>129, 130=>130, 131=>131, 132=>132, 133=>133, 134=>134, 135=>135, 136=>136, 137=>137, 138=>138, 139=>139, 140=>140, 141=>141, 142=>142, 143=>143, 144=>144, 145=>145, 146=>146, 147=>147, 148=>148, 149=>149, 150=>150, 151=>151, 152=>152, 153=>153, 154=>154, 155=>155, 156=>156, 157=>157, 158=>158, 159=>159, 160=>160, 161=>161, 162=>162, 163=>163, 164=>164, 165=>165, 166=>166, 167=>167, 168=>168, 169=>169, 170=>170, 171=>171, 172=>172, 173=>173, 174=>174, 175=>175, 176=>176, 177=>177, 178=>178, 179=>179, 180=>180, 181=>181, 182=>182, 183=>183, 184=>184, 185=>185, 186=>186, 187=>187, 188=>188, 189=>189, 190=>190, 191=>191, 192=>192, 193=>193, 194=>194, 195=>195, 196=>196, 197=>197, 198=>198, 199=>199, 200=>200, 201=>201, 202=>202, 203=>203, 204=>204, 205=>205, 206=>206, 207=>207, 208=>208, 209=>209, 210=>210, 211=>211, 212=>212, 213=>213, 214=>214, 215=>215, 216=>216, 217=>217, 218=>218, 219=>219, 220=>220, 221=>221, 222=>222, 223=>223, 224=>224, 225=>225, 226=>226, 227=>227, 228=>228, 229=>229, 230=>230, 231=>231, 232=>232, 233=>233, 234=>234, 235=>235, 236=>236, 237=>237, 238=>238, 239=>239, 240=>240, 241=>241, 242=>242, 243=>243, 244=>244, 245=>245, 246=>246, 247=>247, 248=>248, 249=>249, 250=>250, 251=>251, 252=>252, 253=>253, 254=>254, 255=>255, 256=>256, 257=>257, 258=>258, 259=>259, 260=>260, 261=>261, 262=>262, 263=>263, 264=>264, 265=>265, 266=>266, 267=>267, 268=>268, 269=>269, 270=>270, 271=>271, 272=>272, 273=>273, 274=>274, 275=>275, 276=>276, 277=>277, 278=>278, 279=>279, 280=>280, 281=>281, 282=>282, 283=>283, 284=>284, 285=>285, 286=>286, 287=>287, 288=>288, 289=>289, 290=>290, 291=>291, 292=>292, 293=>293, 294=>294, 295=>295, 296=>296, 297=>297, 298=>298, 299=>299, 300=>300, 301=>301, 302=>302, 303=>303, 304=>304, 305=>305, 306=>306, 307=>307, 308=>308, 309=>309, 310=>310, 311=>311, 312=>312, 313=>313, 314=>314, 315=>315, 316=>316, 317=>317, 318=>318, 319=>319, 320=>320, 321=>321, 322=>322, 323=>323, 324=>324, 325=>325, 326=>326, 327=>327, 328=>328, 329=>329, 330=>330, 331=>331, 332=>332, 333=>333, 334=>334, 335=>335, 336=>336, 337=>337, 338=>338, 339=>339, 340=>340, 341=>341, 342=>342, 343=>343, 344=>344, 345=>345, 346=>346, 347=>347, 348=>348, 349=>349, 350=>350, 351=>351, 352=>352, 353=>353, 354=>354, 355=>355, 356=>356, 357=>357, 358=>358, 359=>359, 360=>360, 361=>361, 362=>362, 363=>363, 364=>364, 365=>365, 366=>366, 367=>367, 368=>368, 369=>369, 370=>370, 371=>371, 372=>372, 373=>373, 374=>374, 375=>375, 376=>376, 377=>377, 378=>378, 379=>379, 380=>380, 381=>381, 382=>382, 383=>383, 384=>384, 385=>385, 386=>386, 387=>387, 388=>388, 389=>389, 390=>390, 391=>391, 392=>392, 393=>393, 394=>394, 395=>395, 396=>396, 397=>397, 398=>398, 399=>399, 400=>400, 401=>401, 402=>402, 403=>403, 404=>404, 405=>405, 406=>406, 407=>407, 408=>408, 409=>409, 410=>410, 411=>411, 412=>412, 413=>413, 414=>414, 415=>415, 416=>416, 417=>417, 418=>418, 419=>419, 420=>420, 421=>421, 422=>422, 423=>423, 424=>424, 425=>425, 426=>426, 427=>427, 428=>428, 429=>429, 430=>430, 431=>431, 432=>432, 433=>433, 434=>434, 435=>435, 436=>436, 437=>437, 438=>438, 439=>439, 440=>440, 441=>441, 442=>442, 443=>443, 444=>444, 445=>445, 446=>446, 447=>447, 448=>448, 449=>449, 450=>450, 451=>451, 452=>452, 453=>453, 454=>454, 455=>455, 456=>456, 457=>457, 458=>458, 459=>459, 460=>460, 461=>461, 462=>462, 463=>463, 464=>464, 465=>465, 466=>466, 467=>467, 468=>468, 469=>469, 470=>470, 471=>471, 472=>472, 473=>473, 474=>474, 475=>475, 476=>476, 477=>477, 478=>478, 479=>479, 480=>480, 481=>481, 482=>482, 483=>483, 484=>484, 485=>485, 486=>486, 487=>487, 488=>488, 489=>489, 490=>490, 491=>491, 492=>492, 493=>493, 494=>494, 495=>495, 496=>496, 497=>497, 498=>498, 499=>499, 500=>500,}
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 4.596447177
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 4.639894454
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 4.656875482
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 4.638195884
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 4.752055493
built-ruby 5.30335476
built-ruby 5.136351352
built-ruby 5.093668485
built-ruby 5.094187949
built-ruby 5.091365502
-----------------------------------------------------------
vm2_case
i = 0
while i<6_000_000 # while loop 2
case :foo
when :bar
raise
when :baz
raise
when :boo
raise
when :foo
i += 1
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.162350936
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.163400867
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.160771003
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.1609505
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.160908791
built-ruby 0.159453742
built-ruby 0.162180376
built-ruby 0.16114237
built-ruby 0.159755205
built-ruby 0.162193018
-----------------------------------------------------------
vm2_defined_method
class Object
define_method(:m){}
end
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m; m; m; m; m; m; m; m;
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.253986018
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.30203088
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.225114375
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.231331289
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 2.269750882
built-ruby 2.304365027
built-ruby 2.258174015
built-ruby 2.230237563
built-ruby 2.224416651
built-ruby 2.225292384
-----------------------------------------------------------
vm2_dstr
i = 0
x = y = 'z'
while i<6_000_000 # benchmark loop 2
i += 1
str = "foo#{x}bar#{y}baz"
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.195215461
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.201674544
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.198869318
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.206409904
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.20317848
built-ruby 1.214155678
built-ruby 1.187116946
built-ruby 1.192418599
built-ruby 1.187489454
built-ruby 1.190668907
-----------------------------------------------------------
vm2_eval
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
eval("1")
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.573431633
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.057588211
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.132631134
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.235763505
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 12.127797602
built-ruby 11.423063745
built-ruby 11.455188768
built-ruby 11.502370741
built-ruby 11.448392958
built-ruby 11.356286359
-----------------------------------------------------------
vm2_method
def m
nil
end
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m; m; m; m; m; m; m; m;
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.237245105
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.20162888
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.234417917
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.206309315
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.196559071
built-ruby 1.204969585
built-ruby 1.218688558
built-ruby 1.225356964
built-ruby 1.21235504
built-ruby 1.214446293
-----------------------------------------------------------
vm2_method_missing
class C
def method_missing mid
end
end
obj = C.new
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m;
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.78258773
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.848388889
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.766349086
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.759674348
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.869467857
built-ruby 1.757812809
built-ruby 1.755788208
built-ruby 1.830283149
built-ruby 1.73907919
built-ruby 1.808725002
-----------------------------------------------------------
vm2_method_with_block
def m
nil
end
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m{}; m{}; m{}; m{}; m{}; m{}; m{}; m{};
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.369927134
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.355743104
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.390825236
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.377347032
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.363738151
built-ruby 1.362491561
built-ruby 1.38780716
built-ruby 1.384090561
built-ruby 1.364197578
built-ruby 1.355332148
-----------------------------------------------------------
vm2_mutex
require 'thread'
m = Mutex.new
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m.synchronize{}
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.64697692
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.63522827
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.639641452
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.641775721
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.652105445
built-ruby 0.630867777
built-ruby 0.631096412
built-ruby 0.631853884
built-ruby 0.630756971
built-ruby 0.634061511
-----------------------------------------------------------
vm2_poly_method
class C1
def m
1
end
end
class C2
def m
2
end
end
o1 = C1.new
o2 = C2.new
i = 0
while i<6_000_000 # 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
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.892849013
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.861963775
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.815624654
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.981939131
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.823549213
built-ruby 1.814705833
built-ruby 1.814770621
built-ruby 1.812823893
built-ruby 1.823037125
built-ruby 1.824704687
-----------------------------------------------------------
vm2_poly_method_ov
class C1
def m
1
end
end
class C2
def m
2
end
end
o1 = C1.new
o2 = C2.new
i = 0
while i<6_000_000 # 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
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.231704961
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.230371318
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.23445799
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.232702552
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.231765358
built-ruby 0.231019707
built-ruby 0.231478283
built-ruby 0.231902807
built-ruby 0.230337973
built-ruby 0.230039737
-----------------------------------------------------------
vm2_proc
def m &b
b
end
pr = m{
a = 1
}
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
pr.call
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.465992462
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.450616788
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.451133066
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.450978374
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.455488326
built-ruby 0.449374854
built-ruby 0.44827705
built-ruby 0.44932049
built-ruby 0.447584165
built-ruby 0.448189725
-----------------------------------------------------------
vm2_raise1
def rec n
if n > 0
rec n-1
else
raise
end
end
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
begin
rec 1
rescue
# ignore
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.348399836
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.334592646
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.403049377
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.320660929
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 5.373461724
built-ruby 5.558280335
built-ruby 5.595149348
built-ruby 5.502694045
built-ruby 5.521313433
built-ruby 5.488213879
-----------------------------------------------------------
vm2_raise2
def rec n
if n > 0
rec n-1
else
raise
end
end
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
begin
rec 10
rescue
# ignore
end
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 7.803866464
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 7.619855683
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 7.650214738
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 7.601298144
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 7.636543219
built-ruby 7.676698886
built-ruby 7.673801934
built-ruby 7.559160864
built-ruby 7.645511556
built-ruby 7.54940051
-----------------------------------------------------------
vm2_regexp
i = 0
str = 'xxxhogexxx'
while i<6_000_000 # benchmark loop 2
/hoge/ =~ str
i += 1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.996379699
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.993631705
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.991374957
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.993414671
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.993200854
built-ruby 0.992238911
built-ruby 0.991983506
built-ruby 0.991720985
built-ruby 0.991765265
built-ruby 0.992397816
-----------------------------------------------------------
vm2_send
class C
def m
end
end
o = C.new
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
o.__send__ :m
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.3240665
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.335589186
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.3199583
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.318532653
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.318138845
built-ruby 0.338235204
built-ruby 0.321932002
built-ruby 0.327849703
built-ruby 0.321773027
built-ruby 0.321866174
-----------------------------------------------------------
vm2_super
class C
def m
1
end
end
class CC < C
def m
super()
end
end
obj = CC.new
i = 0
while i<6_000_000 # benchmark loop 2
obj.m
i += 1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.434412028
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.434204464
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.434130699
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.440787928
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.434178958
built-ruby 0.449585343
built-ruby 0.441750256
built-ruby 0.441438022
built-ruby 0.440761217
built-ruby 0.441000089
-----------------------------------------------------------
vm2_unif1
i = 0
def m a, b
end
while i<6_000_000 # benchmark loop 2
i += 1
m 100, 200
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.228781268
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.228294245
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.227995284
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.228281175
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.228565694
built-ruby 0.228401294
built-ruby 0.234374138
built-ruby 0.228436592
built-ruby 0.228399781
built-ruby 0.228468721
-----------------------------------------------------------
vm2_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<6_000_000 # benchmark loop 2
obj.m 10
i += 1
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.450867609
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.45182784
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.452106206
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.495850763
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.451940849
built-ruby 0.456826612
built-ruby 0.456295151
built-ruby 0.455726478
built-ruby 0.455675427
built-ruby 0.455558283
-----------------------------------------------------------
vm3_backtrace
# get last backtrace
begin
caller(0, 0)
rescue ArgumentError
alias caller_orig caller
def caller lev, n
caller_orig(lev)[0..n]
end
end
def rec n
if n < 0
100_000.times{
caller(0, 1)
}
else
rec(n-1)
end
end
rec 50
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.112899108
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.112603919
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.112688819
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.112357576
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.112660377
built-ruby 0.111781447
built-ruby 0.11201689
built-ruby 0.111436687
built-ruby 0.111733281
built-ruby 0.112623009
-----------------------------------------------------------
vm3_clearmethodcache
i = 0
while i<200_000
i += 1
Class.new{
def m; end
}
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.297243895
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.309328414
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.30632233
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.304365608
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.30824504
built-ruby 0.313406134
built-ruby 0.315705227
built-ruby 0.316620248
built-ruby 0.313912357
built-ruby 0.317581769
-----------------------------------------------------------
vm3_gc
#! /usr/bin/ruby
5000.times do
100.times do
{"xxxx"=>"yyyy"}
end
GC.start
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.615839692
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.622432254
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.61983926
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.62125771
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.618101733
built-ruby 0.582005876
built-ruby 0.570257621
built-ruby 0.568595375
built-ruby 0.568452353
built-ruby 0.569596881
-----------------------------------------------------------
vm_thread_alive_check1
5_000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.076612468
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.078827871
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.07220144
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.072435102
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 0.072777419
built-ruby 0.114426734
built-ruby 0.110421088
built-ruby 0.111468291
built-ruby 0.112711931
built-ruby 0.117577137
-----------------------------------------------------------
vm_thread_create_join
i = 0
while i<100_000 # benchmark loop 3
i += 1
Thread.new{
}.join
end
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.091711674
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.096589464
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.065626216
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.111731286
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] 1.110455554
built-ruby 1.776013548
built-ruby 1.736041445
built-ruby 1.687214983
built-ruby 1.740708117
built-ruby 1.695793168
-----------------------------------------------------------
vm_thread_mutex1
# one thread, one mutex (no contention)
require 'thread'
m = Mutex.new
r = 0
max = 2000
lmax = max * max
(1..1).map{
Thread.new{
i = 0
while i