2014-09-19 09:01:28 +0000
target 0: cifn (ruby 2.2.0dev (2014-09-19 trunk 47642) [x86_64-linux]) at "gcc/ruby.cifn"
target 1: mdef (ruby 2.2.0dev (2014-09-19 trunk 47642) [x86_64-linux]) at "gcc/ruby.mdef"
-----------------------------------------------------------
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
cifn 0.073828944
cifn 0.078287656
cifn 0.080913523
cifn 0.076048035
cifn 0.078697328
cifn 0.0819409
cifn 0.075562852
cifn 0.083120729
cifn 0.073884537
cifn 0.076943265
mdef 0.07326401
mdef 0.073046688
mdef 0.078029086
mdef 0.073173782
mdef 0.072903177
mdef 0.076067309
mdef 0.073127462
mdef 0.07849978
mdef 0.077207239
mdef 0.073633035
-----------------------------------------------------------
app_aobench
# AO render benchmark
# Original program (C) Syoyo Fujita in Javascript (and other languages)
# https://code.google.com/p/aobench/
# 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
cifn 75.713243899
cifn 74.930807387
cifn 75.839324474
cifn 76.885659563
cifn 76.197197992
cifn 77.624688425
cifn 76.484822441
cifn 76.794678982
cifn 77.00571011
cifn 76.382726347
mdef 76.121598065
mdef 75.028810205
mdef 75.830324974
mdef 75.328985794
mdef 75.209762315
mdef 74.559642344
mdef 74.502688849
mdef 74.285216757
mdef 75.198405817
mdef 76.259802402
-----------------------------------------------------------
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 %>
cifn 1.406502533
cifn 1.410967561
cifn 1.391105608
cifn 1.383991023
cifn 1.389891316
cifn 1.388383847
cifn 1.395219
cifn 1.385571523
cifn 1.403369616
cifn 1.381600003
mdef 1.403610417
mdef 1.422191243
mdef 1.405686592
mdef 1.405551528
mdef 1.416344435
mdef 1.401477823
mdef 1.401617678
mdef 1.391800345
mdef 1.512171845
mdef 1.400319105
-----------------------------------------------------------
app_factorial
def fact(n)
if(n > 1)
n * fact(n-1)
else
1
end
end
100.times {
fact(5000)
}
cifn 1.172189749
cifn 1.179922142
cifn 1.17621432
cifn 1.1787616
cifn 1.171639513
cifn 1.17755592
cifn 1.172999199
cifn 1.175103492
cifn 1.173374666
cifn 1.182313105
mdef 1.18820544
mdef 1.19346802
mdef 1.184779813
mdef 1.192268566
mdef 1.198737152
mdef 1.189903836
mdef 1.192755482
mdef 1.195640681
mdef 1.191537664
mdef 1.191967681
-----------------------------------------------------------
app_fib
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)
cifn 0.687306705
cifn 0.736661639
cifn 0.772780233
cifn 0.780160878
cifn 0.717351101
cifn 0.717754109
cifn 0.751008117
cifn 0.682638215
cifn 0.699568096
cifn 0.721171571
mdef 0.685084578
mdef 0.668254596
mdef 0.68490259
mdef 0.696659031
mdef 0.732441166
mdef 0.682298961
mdef 0.703802197
mdef 0.709111034
mdef 0.675444287
mdef 0.705329683
-----------------------------------------------------------
app_lc_fizzbuzz
#
# FizzBuzz program using only lambda calculus
#
# This program is quoted from
# "Understanding Computation" by Tom Stuart
# http://computationbook.com/
#
# You can understand why this program works fine by reading this book.
#
solution = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] } }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[x]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> n { -> l { -> x { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][l][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][x]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }] } }[-> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> x { f[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { -> n { -> p { -> x { p[n[p][x]] } } }[f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n]][x] }][-> p { -> x { x } }] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][x] }]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]] } }][n]]]] }]
FIRST = -> l { LEFT[RIGHT[l]] }
IF = -> b { b }
LEFT = -> p { p[-> x { -> y { x } } ] }
RIGHT = -> p { p[-> x { -> y { y } } ] }
IS_EMPTY = LEFT
REST = -> l { RIGHT[RIGHT[l]] }
def to_integer(proc)
proc[-> n { n + 1 }][0]
end
def to_boolean(proc)
IF[proc][true][false]
end
def to_array(proc)
array = []
until to_boolean(IS_EMPTY[proc])
array.push(FIRST[proc])
proc = REST[proc]
end
array
end
def to_char(c)
'0123456789BFiuz'.slice(to_integer(c))
end
def to_string(s)
to_array(s).map { |c| to_char(c) }.join
end
answer = to_array(solution).map do |p|
to_string(p)
end
answer_ary = answer.to_a
# puts answer_ary
cifn 97.091869988
cifn 94.820226953
cifn 96.166893285
cifn 94.055559302
cifn 94.596297359
cifn 95.290892465
cifn 98.445368397
cifn 99.470528298
cifn 93.721053698
cifn 94.550142812
mdef 97.389354875
mdef 99.752378151
mdef 97.812774709
mdef 101.112600366
mdef 100.398894011
mdef 99.176704058
mdef 95.100040957
mdef 97.520841998
mdef 99.917898543
mdef 99.173234004
-----------------------------------------------------------
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)
}
}
cifn 1.454239179
cifn 1.513525334
cifn 1.468929904
cifn 1.517569163
cifn 1.534459315
cifn 1.495883306
cifn 1.514567589
cifn 1.507985482
cifn 1.435905328
cifn 1.532280383
mdef 1.463335268
mdef 1.484904856
mdef 1.461383512
mdef 1.510108832
mdef 1.527093035
mdef 1.433060639
mdef 1.44721205
mdef 1.434279616
mdef 1.485354487
mdef 1.530796735
-----------------------------------------------------------
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)
cifn 19.675128821
cifn 20.610204845
cifn 19.549740776
cifn 20.139474203
cifn 19.986859354
cifn 20.147191003
cifn 19.445051548
cifn 20.197592158
cifn 19.750873272
cifn 20.389999225
mdef 19.723705703
mdef 20.325378939
mdef 20.164897821
mdef 20.572403654
mdef 19.042093792
mdef 21.455843509
mdef 19.890725331
mdef 20.567163545
mdef 20.428165436
mdef 20.151455695
-----------------------------------------------------------
app_raise
i = 0
while i<300000
i += 1
begin
raise
rescue
end
end
cifn 0.477565267
cifn 0.472300095
cifn 0.496838299
cifn 0.485951424
cifn 0.463441089
cifn 0.482990925
cifn 0.484108266
cifn 0.481408193
cifn 0.487270968
cifn 0.486672206
mdef 0.473376509
mdef 0.470722356
mdef 0.463361802
mdef 0.456639249
mdef 0.468169699
mdef 0.47301
mdef 0.455221552
mdef 0.457849268
mdef 0.477748254
mdef 0.456169313
-----------------------------------------------------------
app_strconcat
i = 0
while i<2_000_000
"#{1+1} #{1+1} #{1+1}"
i += 1
end
cifn 1.168801645
cifn 1.165958018
cifn 1.14728873
cifn 1.157068423
cifn 1.187484319
cifn 1.169689924
cifn 1.191905317
cifn 1.16561267
cifn 1.230807748
cifn 1.175021313
mdef 1.22203536
mdef 1.203679959
mdef 1.216864989
mdef 1.187799168
mdef 1.194051987
mdef 1.188767533
mdef 1.200727704
mdef 1.195888766
mdef 1.208757605
mdef 1.20233762
-----------------------------------------------------------
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)
cifn 0.920353761
cifn 0.981373852
cifn 0.973770582
cifn 0.96637947
cifn 1.007401985
cifn 0.927890383
cifn 0.918810022
cifn 1.034812473
cifn 0.973645808
cifn 0.923309507
mdef 0.925447865
mdef 1.015820136
mdef 0.959000842
mdef 0.987563553
mdef 1.014534478
mdef 0.921478518
mdef 0.941263035
mdef 1.007267463
mdef 0.980255766
mdef 0.905533395
-----------------------------------------------------------
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)
cifn 0.748211758
cifn 0.802484237
cifn 0.755345817
cifn 0.760513512
cifn 0.741907736
cifn 0.747335754
cifn 0.74776568
cifn 0.957157599
cifn 0.999159757
cifn 0.776539275
mdef 0.83011
mdef 0.80313758
mdef 0.958872032
mdef 0.804912445
mdef 0.753686777
mdef 0.780179873
mdef 0.774178095
mdef 0.760816653
mdef 0.800025346
mdef 0.863362313
-----------------------------------------------------------
app_uri
require 'uri'
100_000.times{
uri = URI.parse('http://www.ruby-lang.org')
uri.scheme
uri.host
uri.port
}
cifn 1.191102422
cifn 1.22094662
cifn 1.223685664
cifn 1.212963385
cifn 1.215603114
cifn 1.210197785
cifn 1.209043109
cifn 1.216873979
cifn 1.201338802
cifn 1.211474112
mdef 1.250200838
mdef 1.335923881
mdef 1.251587799
mdef 1.245443038
mdef 1.248697426
mdef 1.25045553
mdef 1.244783813
mdef 1.242402256
mdef 1.256709544
mdef 1.250943669
-----------------------------------------------------------
hash_aref_miss
h = {}
strs = ('a'..'z').to_a.map!(&:freeze)
strs.each { |s| h[s] = s }
strs = ('A'..'Z').to_a
200_000.times { strs.each { |s| h[s] } }
cifn 0.569112631
cifn 0.584249272
cifn 0.560212901
cifn 0.575889015
cifn 0.56469548
cifn 0.582458285
cifn 0.564638694
cifn 0.611034661
cifn 0.563249459
cifn 0.588871314
mdef 0.565247605
mdef 0.552257189
mdef 0.583339804
mdef 0.555996333
mdef 0.579432945
mdef 0.583755417
mdef 0.571664037
mdef 0.580904314
mdef 0.570860855
mdef 0.562304726
-----------------------------------------------------------
hash_aref_str
h = {}
strs = ('a'..'z').to_a.map!(&:freeze)
strs.each { |s| h[s] = s }
200_000.times { strs.each { |s| h[s] } }
cifn 0.541229954
cifn 0.550546158
cifn 0.545577647
cifn 0.553125915
cifn 0.527295269
cifn 0.534515885
cifn 0.54419218
cifn 0.525052612
cifn 0.56126827
cifn 0.534517087
mdef 0.542593049
mdef 0.537040282
mdef 0.549370284
mdef 0.529081229
mdef 0.526891391
mdef 0.531401956
mdef 0.534405155
mdef 0.545665309
mdef 0.541308276
mdef 0.538613241
-----------------------------------------------------------
hash_aref_sym
h = {}
syms = ('a'..'z').to_a.map(&:to_sym)
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
cifn 0.77470492
cifn 0.780810189
cifn 0.776069302
cifn 0.797481168
cifn 0.775913021
cifn 0.781233006
cifn 0.762242367
cifn 0.745946015
cifn 0.76207053
cifn 0.781287834
mdef 0.767838234
mdef 0.781841351
mdef 0.758827366
mdef 0.752102067
mdef 0.798747579
mdef 0.754150699
mdef 0.801361427
mdef 0.756766351
mdef 0.771888465
mdef 0.760892244
-----------------------------------------------------------
hash_aref_sym_long
h = {}
syms = %w[puts warn syswrite write stat bacon lettuce tomato
some symbols in this array may already be interned others should not be
hash browns make good breakfast but not cooked using prime numbers
shift for division entries delete_if keys exist?
].map!(&:to_sym)
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
cifn 1.83299439
cifn 1.695380766
cifn 1.62539726
cifn 1.710657592
cifn 1.691088241
cifn 1.664329316
cifn 1.628945
cifn 1.686701938
cifn 1.613718183
cifn 1.673022511
mdef 1.599784484
mdef 1.642546744
mdef 1.711008992
mdef 1.713107782
mdef 1.682439089
mdef 1.639118838
mdef 1.640587419
mdef 1.61955292
mdef 1.631393375
mdef 1.691587045
-----------------------------------------------------------
hash_flatten
h = {}
10000.times do |i|
h[i] = nil
end
1000.times do
h.flatten
end
cifn 0.651693981
cifn 0.64941614
cifn 0.647306282
cifn 0.653658206
cifn 0.654396382
cifn 0.653489707
cifn 0.651530604
cifn 0.652485894
cifn 0.651196398
cifn 0.652928104
mdef 0.645241425
mdef 0.64557226
mdef 0.647596087
mdef 0.646091417
mdef 0.649178932
mdef 0.6447751
mdef 0.644474763
mdef 0.648453017
mdef 0.645859335
mdef 0.642636029
-----------------------------------------------------------
hash_ident_num
h = {}.compare_by_identity
nums = (1..26).to_a
nums.each { |n| h[n] = n }
200_000.times { nums.each { |n| h[n] } }
cifn 0.393905515
cifn 0.399344408
cifn 0.422180022
cifn 0.428076849
cifn 0.408793155
cifn 0.394903225
cifn 0.395151057
cifn 0.398509307
cifn 0.394966859
cifn 0.413089087
mdef 0.396971843
mdef 0.402839314
mdef 0.392248322
mdef 0.394098022
mdef 0.391652461
mdef 0.412438884
mdef 0.388988236
mdef 0.40617678
mdef 0.395776788
mdef 0.389554995
-----------------------------------------------------------
hash_ident_obj
h = {}.compare_by_identity
objs = 26.times.map { Object.new }
objs.each { |o| h[o] = o }
200_000.times { objs.each { |o| h[o] } }
cifn 0.421862526
cifn 0.483150415
cifn 0.402994584
cifn 0.400422678
cifn 0.406295141
cifn 0.409119282
cifn 0.407995953
cifn 0.400507132
cifn 0.401717873
cifn 0.408155621
mdef 0.423259998
mdef 0.418052365
mdef 0.413722424
mdef 0.427840469
mdef 0.412986219
mdef 0.433713747
mdef 0.446972066
mdef 0.40963505
mdef 0.404674956
mdef 0.420544912
-----------------------------------------------------------
hash_ident_str
h = {}.compare_by_identity
strs = ('a'..'z').to_a
strs.each { |s| h[s] = s }
200_000.times { strs.each { |s| h[s] } }
cifn 0.422486737
cifn 0.415710023
cifn 0.424511836
cifn 0.417518491
cifn 0.419725621
cifn 0.42145399
cifn 0.422436999
cifn 0.426750247
cifn 0.401545853
cifn 0.429696089
mdef 0.418454239
mdef 0.414069904
mdef 0.411277933
mdef 0.409871988
mdef 0.413767843
mdef 0.42194736
mdef 0.402017
mdef 0.419290318
mdef 0.421724525
mdef 0.433266902
-----------------------------------------------------------
hash_ident_sym
h = {}.compare_by_identity
syms = ('a'..'z').to_a.map(&:to_sym)
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
cifn 0.423814744
cifn 0.417272117
cifn 0.42221472
cifn 0.427435995
cifn 0.437124304
cifn 0.419513966
cifn 0.431021747
cifn 0.422311621
cifn 0.432082588
cifn 0.426000136
mdef 0.439136808
mdef 0.455053488
mdef 0.41318681
mdef 0.42432397
mdef 0.406917798
mdef 0.417050228
mdef 0.428582212
mdef 0.429663622
mdef 0.41813153
mdef 0.419566936
-----------------------------------------------------------
hash_keys
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.keys
end
cifn 0.270495973
cifn 0.266260027
cifn 0.264867628
cifn 0.262702642
cifn 0.265760629
cifn 0.265239174
cifn 0.266508402
cifn 0.271513145
cifn 0.272280705
cifn 0.265162047
mdef 0.267077851
mdef 0.267540051
mdef 0.269731318
mdef 0.268625989
mdef 0.268422445
mdef 0.267981517
mdef 0.270806124
mdef 0.27011668
mdef 0.265370369
mdef 0.267893987
-----------------------------------------------------------
hash_shift
h = {}
10000.times do |i|
h[i] = nil
end
50000.times do
k, v = h.shift
h[k] = v
end
cifn 0.054077528
cifn 0.054176783
cifn 0.053697416
cifn 0.05369884
cifn 0.05496447
cifn 0.054815357
cifn 0.053783759
cifn 0.053374718
cifn 0.05342026
cifn 0.055495059
mdef 0.053741085
mdef 0.054484064
mdef 0.054743044
mdef 0.053695536
mdef 0.053432123
mdef 0.054979114
mdef 0.0538816
mdef 0.053892819
mdef 0.053877501
mdef 0.053956028
-----------------------------------------------------------
hash_values
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.values
end
cifn 0.277444634
cifn 0.269512323
cifn 0.27107876
cifn 0.278998939
cifn 0.278277507
cifn 0.276328575
cifn 0.27681924
cifn 0.275997611
cifn 0.283598355
cifn 0.292074526
mdef 0.280039446
mdef 0.278427415
mdef 0.286984046
mdef 0.278194727
mdef 0.288731091
mdef 0.285596115
mdef 0.278423285
mdef 0.280336899
mdef 0.27966514
mdef 0.285901883
-----------------------------------------------------------
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)
cifn 2.196009142
cifn 2.142346985
cifn 2.12754715
cifn 2.092625866
cifn 2.143752265
cifn 2.135034709
cifn 2.088696441
cifn 2.10488775
cifn 2.123753373
cifn 2.134516306
mdef 2.067828326
mdef 2.142862759
mdef 2.079015662
mdef 2.124554137
mdef 2.222016317
mdef 2.129701547
mdef 2.131774244
mdef 2.095726715
mdef 2.130659665
mdef 2.115173688
-----------------------------------------------------------
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
}
cifn 2.436736973
cifn 2.416651562
cifn 2.434397356
cifn 2.515610499
cifn 2.462597207
cifn 2.331278634
cifn 2.756821869
cifn 2.428779436
cifn 2.430990283
cifn 2.412467531
mdef 2.511763084
mdef 2.451663698
mdef 2.426856202
mdef 2.457180504
mdef 2.445351894
mdef 2.47286084
mdef 2.443840706
mdef 2.46059042
mdef 2.43638197
mdef 2.438625677
-----------------------------------------------------------
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
}
cifn 1.531733861
cifn 1.390887487
cifn 1.381107314
cifn 1.415636811
cifn 1.395102702
cifn 1.441442114
cifn 1.379490248
cifn 1.588994009
cifn 1.384543189
cifn 1.381132817
mdef 1.450506231
mdef 1.41424515
mdef 1.397334069
mdef 1.412146387
mdef 1.565379124
mdef 1.395265937
mdef 1.41909939
mdef 1.435445386
mdef 1.405305792
mdef 1.407369125
-----------------------------------------------------------
io_select
# IO.select performance
w = [ IO.pipe[1] ];
nr = 1000000
nr.times {
IO.select nil, w
}
cifn 2.205470513
cifn 2.249221562
cifn 2.169350818
cifn 2.246380813
cifn 2.247542561
cifn 2.232076595
cifn 2.221414904
cifn 2.148769172
cifn 2.202924337
cifn 2.209763864
mdef 2.231992503
mdef 2.228120995
mdef 2.214226632
mdef 2.212831253
mdef 2.2226019
mdef 2.238171386
mdef 2.246066674
mdef 2.225422395
mdef 2.241009481
mdef 2.231050254
-----------------------------------------------------------
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
cifn 2.541155025
cifn 2.573172099
cifn 2.577531733
cifn 2.579220846
cifn 2.506815968
cifn 2.623166605
cifn 2.61461974
cifn 2.558523306
cifn 2.56598193
cifn 2.547265245
mdef 2.585103572
mdef 2.604102131
mdef 2.607514498
mdef 2.550660619
mdef 2.576319834
mdef 2.647231321
mdef 2.516635017
mdef 2.61980203
mdef 2.660319728
mdef 2.604976089
-----------------------------------------------------------
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
cifn 0.055021157
cifn 0.055404989
cifn 0.055399478
cifn 0.055258864
cifn 0.055216334
cifn 0.055371921
cifn 0.056082462
cifn 0.055570369
cifn 0.055365404
cifn 0.055282391
mdef 0.055296138
mdef 0.055544699
mdef 0.055262795
mdef 0.055593951
mdef 0.055291155
mdef 0.055281284
mdef 0.054877842
mdef 0.05450681
mdef 0.054702671
mdef 0.054513404
-----------------------------------------------------------
loop_for
for i in 1..30_000_000
#
end
cifn 1.58242479
cifn 1.527633926
cifn 1.545105953
cifn 1.582233707
cifn 1.602599654
cifn 1.505665955
cifn 1.537976367
cifn 1.538948417
cifn 1.540555732
cifn 1.533019583
mdef 1.498462248
mdef 1.585259183
mdef 1.603118059
mdef 1.517637377
mdef 1.586868639
mdef 1.596308982
mdef 1.587738219
mdef 1.522779435
mdef 1.55713334
mdef 1.585804586
-----------------------------------------------------------
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
cifn 1.093829517
cifn 1.095050188
cifn 1.0715639
cifn 1.093510148
cifn 1.077391672
cifn 1.082097578
cifn 1.117277578
cifn 1.077043638
cifn 1.129426286
cifn 1.089812977
mdef 1.121011155
mdef 1.100130929
mdef 1.134800336
mdef 1.097543342
mdef 1.086665694
mdef 1.098979833
mdef 1.111600853
mdef 1.085564753
mdef 1.105670802
mdef 1.142815334
-----------------------------------------------------------
loop_times
30_000_000.times{|e|}
cifn 1.446071788
cifn 1.450896871
cifn 1.419717083
cifn 1.422062933
cifn 1.414590478
cifn 1.406272673
cifn 1.480466661
cifn 1.428805336
cifn 1.429134513
cifn 1.460532118
mdef 1.397223884
mdef 1.402684425
mdef 1.434979092
mdef 1.411396622
mdef 1.388456463
mdef 1.403945221
mdef 1.415150263
mdef 1.421707581
mdef 1.421960962
mdef 1.43479193
-----------------------------------------------------------
loop_whileloop
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
end
cifn 0.681211716
cifn 0.683891239
cifn 0.679289509
cifn 0.684715713
cifn 0.679411536
cifn 0.68234314
cifn 0.679685474
cifn 0.679206802
cifn 0.679730077
cifn 0.67868878
mdef 0.673616962
mdef 0.673939357
mdef 0.674467535
mdef 0.673024925
mdef 0.671211878
mdef 0.673873666
mdef 0.671697257
mdef 0.673084344
mdef 0.672531392
mdef 0.674023113
-----------------------------------------------------------
loop_whileloop2
i = 0
while i< 6_000_000 # benchmark loop 2
i += 1
end
cifn 0.160105749
cifn 0.161240941
cifn 0.160072892
cifn 0.161315542
cifn 0.160225175
cifn 0.160762789
cifn 0.160669456
cifn 0.15953594
cifn 0.159611855
cifn 0.15939537
mdef 0.158718463
mdef 0.158980344
mdef 0.159188231
mdef 0.158714092
mdef 0.159043512
mdef 0.158651213
mdef 0.159528251
mdef 0.159253266
mdef 0.159969103
mdef 0.15895581
-----------------------------------------------------------
securerandom
require "securerandom"
20_0000.times do
SecureRandom.random_number(100)
end
cifn 1.041231657
cifn 1.030559988
cifn 1.017115155
cifn 1.041103486
cifn 1.048223533
cifn 1.038595459
cifn 1.041095075
cifn 1.017030793
cifn 1.064594695
cifn 1.067815638
mdef 1.019871327
mdef 1.026805705
mdef 1.02017636
mdef 1.012392952
mdef 1.01379757
mdef 1.01257389
mdef 1.002626545
mdef 1.018165115
mdef 1.030216728
mdef 0.991345095
-----------------------------------------------------------
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)
cifn 0.809544194
cifn 0.846628716
cifn 0.78419709
cifn 0.737623099
cifn 0.776427586
cifn 0.872639309
cifn 0.790598655
cifn 0.789111508
cifn 0.810478972
cifn 0.868572216
mdef 0.788401328
mdef 0.798504533
mdef 0.739343845
mdef 0.788216904
mdef 0.793211537
mdef 0.786944895
mdef 0.802092726
mdef 0.79331468
mdef 0.726039369
mdef 0.752176929
-----------------------------------------------------------
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}"
cifn 0.967840669
cifn 1.015073348
cifn 0.983587664
cifn 1.003393573
cifn 0.958280913
cifn 0.987418604
cifn 0.958887498
cifn 0.964645974
cifn 0.962266944
cifn 0.961503152
mdef 0.95322457
mdef 0.964860484
mdef 0.953796668
mdef 1.05398397
mdef 0.985258426
mdef 0.970619258
mdef 0.956319202
mdef 0.95451872
mdef 0.965418872
mdef 0.966484599
-----------------------------------------------------------
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
cifn 8.028306236
cifn 7.7912168
cifn 8.129588347
cifn 7.802404894
cifn 7.893539693
cifn 7.777896509
cifn 7.842022018
cifn 7.887764232
cifn 7.9218262
cifn 7.758031601
mdef 7.744485147
mdef 7.697869983
mdef 7.672370929
mdef 7.601719142
mdef 7.673730678
mdef 7.726008268
mdef 7.761750283
mdef 7.568542281
mdef 7.572456295
mdef 7.822077322
-----------------------------------------------------------
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
cifn 3.950203477
cifn 3.898015726
cifn 3.856124635
cifn 3.888482214
cifn 3.971870512
cifn 3.893258093
cifn 3.896251346
cifn 3.896594567
cifn 3.982950272
cifn 4.083474297
mdef 3.954227935
mdef 3.867452902
mdef 3.898007184
mdef 3.837927807
mdef 3.838933719
mdef 3.960140261
mdef 3.894009959
mdef 3.818040471
mdef 3.906915073
mdef 3.848945559
-----------------------------------------------------------
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}"
cifn 0.310482296
cifn 0.310748992
cifn 0.310103189
cifn 0.309896219
cifn 0.310392317
cifn 0.31071967
cifn 0.310996079
cifn 0.312408627
cifn 0.314593857
cifn 0.311379881
mdef 0.291908069
mdef 0.293125105
mdef 0.29306341
mdef 0.292661272
mdef 0.29249162
mdef 0.293804712
mdef 0.293303678
mdef 0.291075663
mdef 0.29131101
mdef 0.292004734
-----------------------------------------------------------
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
cifn 0.521129668
cifn 0.517695224
cifn 0.522168645
cifn 0.518006432
cifn 0.551584455
cifn 0.549539243
cifn 0.52705081
cifn 0.551533854
cifn 0.522138842
cifn 0.519122592
mdef 0.489353378
mdef 0.505734402
mdef 0.512179971
mdef 0.474983373
mdef 0.492929955
mdef 0.483982557
mdef 0.495878733
mdef 0.493341292
mdef 0.477737747
mdef 0.492097732
-----------------------------------------------------------
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)}"
cifn 1.713855488
cifn 1.711603285
cifn 1.674693428
cifn 1.703563428
cifn 1.700640635
cifn 1.72583783
cifn 1.709339492
cifn 1.699685699
cifn 1.712495305
cifn 1.708674859
mdef 1.762780382
mdef 1.76700402
mdef 1.727653767
mdef 1.744423314
mdef 1.753175761
mdef 1.74259733
mdef 1.809749346
mdef 1.722876725
mdef 1.732543375
mdef 1.735738899
-----------------------------------------------------------
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)
cifn 2.345581989
cifn 2.361449679
cifn 2.391149759
cifn 2.483490196
cifn 2.378036652
cifn 2.394446229
cifn 2.39088362
cifn 2.464824671
cifn 2.412964833
cifn 2.536728165
mdef 2.184854462
mdef 2.237332868
mdef 2.259689206
mdef 2.1896095
mdef 2.175866118
mdef 2.17979755
mdef 2.252604531
mdef 2.245714943
mdef 2.233161137
mdef 2.227640657
-----------------------------------------------------------
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) }
cifn 1.207734028
cifn 1.288041508
cifn 1.209269614
cifn 1.209719448
cifn 1.251976156
cifn 1.201905072
cifn 1.21818701
cifn 1.223110518
cifn 1.217313875
cifn 1.21628454
mdef 1.255260004
mdef 1.230472031
mdef 1.263983157
mdef 1.24526052
mdef 1.252788616
mdef 1.252894415
mdef 1.441509465
mdef 1.244041483
mdef 1.252152685
mdef 1.254754586
-----------------------------------------------------------
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
cifn 3.101977678
cifn 3.216467856
cifn 3.206117015
cifn 3.216010027
cifn 3.135165343
cifn 3.236132151
cifn 3.183496206
cifn 3.084858397
cifn 3.247944236
cifn 3.280097311
mdef 3.216200558
mdef 3.218555351
mdef 3.121252684
mdef 3.16176034
mdef 3.323705057
mdef 3.181894219
mdef 3.20224753
mdef 3.289108162
mdef 3.136803549
mdef 3.25199649
-----------------------------------------------------------
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]}"
cifn 0.760532359
cifn 0.76146509
cifn 0.763065407
cifn 0.778129693
cifn 0.79202971
cifn 0.771522213
cifn 0.761843534
cifn 0.802421791
cifn 0.782980408
cifn 0.782090049
mdef 0.762528275
mdef 0.744946348
mdef 0.744099233
mdef 0.745149059
mdef 0.748454715
mdef 0.751169321
mdef 0.768572177
mdef 0.751950393
mdef 0.748165311
mdef 0.750436356
-----------------------------------------------------------
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!!!
cifn 3.71619925
cifn 3.89555381
cifn 3.943366912
cifn 3.899034598
cifn 4.093054345
cifn 3.687610556
cifn 3.726178727
cifn 3.818875021
cifn 3.924151137
cifn 3.771474257
mdef 3.969740391
mdef 3.745174074
mdef 3.992319182
mdef 3.90870897
mdef 3.685358361
mdef 3.861053168
mdef 3.734705137
mdef 3.720578533
mdef 3.927284781
mdef 3.744863122
-----------------------------------------------------------
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)
cifn 1.919701799
cifn 1.875121684
cifn 1.900964417
cifn 1.888100359
cifn 1.85135414
cifn 1.941056315
cifn 1.880630609
cifn 1.953924681
cifn 1.925785807
cifn 1.901309145
mdef 1.931802589
mdef 1.956306899
mdef 1.998058433
mdef 1.935219454
mdef 1.916560255
mdef 1.912337673
mdef 1.923991598
mdef 1.951427832
mdef 1.914051649
mdef 1.824215556
-----------------------------------------------------------
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
cifn 1.265542465
cifn 1.264127308
cifn 1.281638414
cifn 1.286284736
cifn 1.29552388
cifn 1.268895384
cifn 1.259633893
cifn 1.262628015
cifn 1.437608436
cifn 1.273370595
mdef 1.262271422
mdef 1.294807738
mdef 1.261134765
mdef 1.258309017
mdef 1.26665268
mdef 1.280486204
mdef 1.291959339
mdef 1.275202137
mdef 1.278997445
mdef 1.275662675
-----------------------------------------------------------
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
cifn 2.411062033
cifn 2.471807646
cifn 2.507071917
cifn 2.351124048
cifn 2.408210523
cifn 2.398388068
cifn 2.423122009
cifn 2.351342192
cifn 2.359934937
cifn 2.411535174
mdef 2.36040974
mdef 2.393851735
mdef 2.346745505
mdef 2.371119745
mdef 2.389912736
mdef 2.364234375
mdef 2.371274311
mdef 2.348470833
mdef 2.416721831
mdef 2.351605072
-----------------------------------------------------------
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
cifn 2.530632014
cifn 2.427741531
cifn 2.446737328
cifn 2.405301856
cifn 2.375387133
cifn 2.425588555
cifn 2.403291478
cifn 2.382127422
cifn 2.42366299
cifn 2.415977391
mdef 2.374657543
mdef 2.46452826
mdef 2.37877774
mdef 2.426175506
mdef 2.386542375
mdef 2.393656638
mdef 2.432447982
mdef 2.384210572
mdef 2.355370925
mdef 2.393376078
-----------------------------------------------------------
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
cifn 0.810596095
cifn 0.785564562
cifn 0.799842266
cifn 0.760009118
cifn 0.78864585
cifn 0.788837225
cifn 0.838755477
cifn 0.785968321
cifn 0.804149167
cifn 0.816325291
mdef 0.77517411
mdef 0.754598691
mdef 0.75536834
mdef 0.769772767
mdef 0.800764005
mdef 0.7520622
mdef 0.770734963
mdef 0.780774015
mdef 0.764320057
mdef 0.762336946
-----------------------------------------------------------
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
cifn 2.863492647
cifn 2.89206756
cifn 2.910779177
cifn 2.86374023
cifn 2.84237282
cifn 2.886974922
cifn 2.88954713
cifn 2.823380798
cifn 2.922299401
cifn 2.882274553
mdef 2.846929373
mdef 2.920284901
mdef 2.847984886
mdef 2.809682773
mdef 2.887282636
mdef 2.858284717
mdef 2.872594008
mdef 2.881310768
mdef 2.904204738
mdef 2.94199846
-----------------------------------------------------------
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
cifn 1.235313901
cifn 1.243343835
cifn 1.24844457
cifn 1.236610334
cifn 1.231994671
cifn 1.240798792
cifn 1.245008395
cifn 1.246616938
cifn 1.234663442
cifn 1.244345963
mdef 1.236591489
mdef 1.228761854
mdef 1.233193047
mdef 1.230902688
mdef 1.230646249
mdef 1.23442475
mdef 1.255767775
mdef 1.249124811
mdef 1.262494132
mdef 1.257023469
-----------------------------------------------------------
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)
cifn 1.668277589
cifn 1.769352286
cifn 1.681125141
cifn 1.763249385
cifn 1.774899917
cifn 1.665251584
cifn 1.760624074
cifn 1.778584294
cifn 1.663526469
cifn 1.772856356
mdef 1.744243232
mdef 1.761647892
mdef 1.644469391
mdef 1.643609497
mdef 1.648255307
mdef 1.753987232
mdef 1.762615605
mdef 1.744957328
mdef 1.648065043
mdef 1.637326232
-----------------------------------------------------------
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
cifn 0.679462385
cifn 0.654761067
cifn 0.671829635
cifn 0.651435503
cifn 0.646830934
cifn 0.659912791
cifn 0.648653344
cifn 0.652103948
cifn 0.648554128
cifn 0.679321747
mdef 0.667896411
mdef 0.643046743
mdef 0.660575688
mdef 0.690609986
mdef 0.679317923
mdef 0.741930304
mdef 0.678551077
mdef 0.670714167
mdef 0.652367623
mdef 0.677880908
-----------------------------------------------------------
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
cifn 2.356662522
cifn 2.394040635
cifn 2.36542807
cifn 2.446815177
cifn 2.5412116
cifn 2.480445711
cifn 2.484484589
cifn 2.43844324
cifn 2.41926234
cifn 2.406417345
mdef 2.327038518
mdef 2.389591837
mdef 2.419504405
mdef 2.286756602
mdef 2.442621136
mdef 2.419492087
mdef 2.374863135
mdef 2.405172764
mdef 2.374847957
mdef 2.305643057
-----------------------------------------------------------
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
cifn 1.813241157
cifn 1.908196593
cifn 1.884350215
cifn 1.834691162
cifn 1.783743127
cifn 1.833149329
cifn 1.760796967
cifn 1.779685441
cifn 1.798821885
cifn 1.820942306
mdef 1.781051714
mdef 1.801353904
mdef 1.779847572
mdef 1.802247095
mdef 1.900483067
mdef 1.81066926
mdef 1.75869066
mdef 2.092335993
mdef 1.792006893
mdef 1.797308798
-----------------------------------------------------------
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
cifn 1.926506243
cifn 2.080139322
cifn 1.903193289
cifn 1.916832607
cifn 2.087277012
cifn 1.934493809
cifn 1.912208421
cifn 1.917097179
cifn 1.902758435
cifn 2.025090044
mdef 1.854263206
mdef 2.158592033
mdef 1.847709814
mdef 2.054731598
mdef 1.881041746
mdef 1.99901162
mdef 1.90009493
mdef 1.925291167
mdef 1.910439955
mdef 1.972420754
-----------------------------------------------------------
vm1_block
def m
yield
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m{
}
end
cifn 2.739188126
cifn 2.593793944
cifn 2.597183531
cifn 2.6206001
cifn 2.794912109
cifn 2.749554749
cifn 2.681789257
cifn 2.620809054
cifn 2.601726067
cifn 2.608442576
mdef 2.594182081
mdef 2.852355563
mdef 2.80382276
mdef 3.034260056
mdef 2.60773116
mdef 3.033513256
mdef 2.62049102
mdef 2.59186917
mdef 2.589520545
mdef 2.696553475
-----------------------------------------------------------
vm1_const
Const = 1
i = 0
while i<30_000_000 # while loop 1
i += 1
j = Const
k = Const
end
cifn 0.972037691
cifn 0.971362716
cifn 0.979472011
cifn 0.974437282
cifn 0.978156859
cifn 0.970711152
cifn 0.976301112
cifn 0.970687004
cifn 0.969804755
cifn 0.975036865
mdef 0.976776119
mdef 1.007399042
mdef 0.973203053
mdef 0.963334367
mdef 0.967196548
mdef 0.972776068
mdef 1.039734441
mdef 0.967916781
mdef 1.173601353
mdef 0.966027429
-----------------------------------------------------------
vm1_ensure
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
begin
begin
ensure
end
ensure
end
end
cifn 0.72936288
cifn 0.754680222
cifn 0.729472201
cifn 0.728362866
cifn 0.72898118
cifn 0.729703415
cifn 0.729939894
cifn 0.726851001
cifn 0.727327613
cifn 0.727577744
mdef 0.720495964
mdef 0.720158139
mdef 0.722593732
mdef 0.717573656
mdef 0.717794427
mdef 0.719471725
mdef 0.71856549
mdef 0.755973601
mdef 0.718357833
mdef 0.722040203
-----------------------------------------------------------
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
cifn 5.572750043
cifn 5.850667863
cifn 5.952911642
cifn 5.749008724
cifn 5.749030302
cifn 5.946668855
cifn 5.470101248
cifn 6.04204778
cifn 5.631208779
cifn 6.054381137
mdef 5.788830378
mdef 5.780526081
mdef 5.569618878
mdef 5.685555209
mdef 6.24540432
mdef 5.877095768
mdef 5.870819407
mdef 5.7578672
mdef 5.951467629
mdef 5.690779833
-----------------------------------------------------------
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
cifn 11.586331597
cifn 11.623869395
cifn 11.677573248
cifn 11.518013981
cifn 11.422261956
cifn 11.44077973
cifn 11.548960286
cifn 11.394500928
cifn 11.574943926
cifn 11.461526595
mdef 11.84371227
mdef 11.459026685
mdef 11.472825038
mdef 11.49419716
mdef 11.421501134
mdef 11.408418412
mdef 11.312823373
mdef 11.505859045
mdef 11.414124336
mdef 11.453311156
-----------------------------------------------------------
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
cifn 15.335992227
cifn 14.81393729
cifn 14.825300682
cifn 14.718100452
cifn 15.011479748
cifn 15.078184613
cifn 15.137030091
cifn 15.055540704
cifn 14.824348185
cifn 14.743974112
mdef 14.789466344
mdef 14.988655708
mdef 14.955577556
mdef 14.750649513
mdef 14.867142385
mdef 14.796039703
mdef 15.065836635
mdef 14.734855193
mdef 14.801878968
mdef 15.083321502
-----------------------------------------------------------
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
cifn 13.230342631
cifn 13.240147915
cifn 13.304192953
cifn 13.407499448
cifn 13.379057729
cifn 13.231284557
cifn 13.28622268
cifn 13.351648667
cifn 13.220276363
cifn 13.474602661
mdef 13.320306853
mdef 13.192688604
mdef 13.298348712
mdef 13.214905536
mdef 13.221222841
mdef 13.167672215
mdef 13.667540551
mdef 13.294347937
mdef 13.1793263
mdef 13.224099269
-----------------------------------------------------------
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
cifn 12.201849712
cifn 12.360916761
cifn 12.326790236
cifn 12.716134352
cifn 12.210426639
cifn 12.4349588
cifn 12.324273342
cifn 12.290687691
cifn 12.219651495
cifn 12.376009761
mdef 12.212874265
mdef 12.321228816
mdef 12.235733555
mdef 12.509400795
mdef 12.317025248
mdef 12.383859576
mdef 12.385455528
mdef 12.587738837
mdef 12.341760138
mdef 12.386159009
-----------------------------------------------------------
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
cifn 1.639712737
cifn 1.42684006
cifn 1.401841432
cifn 1.412653565
cifn 1.626215737
cifn 1.407665387
cifn 1.411499297
cifn 1.421513205
cifn 1.416437667
cifn 1.40410068
mdef 1.410979196
mdef 1.407234418
mdef 1.414506081
mdef 1.40967045
mdef 1.423924418
mdef 1.398394126
mdef 1.415822916
mdef 1.578369967
mdef 1.402646402
mdef 1.396460829
-----------------------------------------------------------
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
cifn 1.394393208
cifn 1.707432968
cifn 1.384876429
cifn 1.405277807
cifn 1.428851671
cifn 1.388580467
cifn 1.4602562
cifn 1.556004473
cifn 1.381774487
cifn 1.374625284
mdef 1.389296112
mdef 1.451914882
mdef 1.42284011
mdef 1.377880739
mdef 1.488206652
mdef 1.394876178
mdef 1.382378429
mdef 1.422772661
mdef 1.369676096
mdef 1.403181966
-----------------------------------------------------------
vm1_ivar
@a = 1
i = 0
while i<30_000_000 # while loop 1
i += 1
j = @a
k = @a
end
cifn 1.07697243
cifn 1.06045916
cifn 1.286099334
cifn 1.765260561
cifn 1.063461989
cifn 1.307101232
cifn 1.270971398
cifn 1.048101952
cifn 1.382176682
cifn 1.334068729
mdef 1.134791282
mdef 1.04155495
mdef 1.061580115
mdef 1.046911702
mdef 1.310778385
mdef 1.106503237
mdef 1.063730271
mdef 1.310783488
mdef 1.05613748
mdef 1.154467318
-----------------------------------------------------------
vm1_ivar_set
i = 0
while i<30_000_000 # while loop 1
i += 1
@a = 1
@b = 2
end
cifn 1.271872833
cifn 1.504091903
cifn 1.228425771
cifn 1.338329443
cifn 1.270166677
cifn 1.479585456
cifn 1.273887647
cifn 1.218475695
cifn 1.210298076
cifn 1.333493802
mdef 1.21524614
mdef 1.243613909
mdef 1.211617616
mdef 1.250788235
mdef 1.23615106
mdef 1.216176151
mdef 1.224322333
mdef 1.215876992
mdef 1.232632824
mdef 1.247799108
-----------------------------------------------------------
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
cifn 1.24747899
cifn 1.441869995
cifn 1.238421305
cifn 1.371440546
cifn 1.410579566
cifn 1.368417527
cifn 1.243436235
cifn 1.471221308
cifn 1.44085131
cifn 1.371612691
mdef 1.245323775
mdef 1.248472373
mdef 1.246138335
mdef 1.245883824
mdef 1.243231478
mdef 1.247923225
mdef 1.247726202
mdef 1.245726454
mdef 1.284972747
mdef 1.247491872
-----------------------------------------------------------
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
cifn 2.36633178
cifn 2.229284065
cifn 2.396940851
cifn 2.239931748
cifn 2.305593938
cifn 2.602924445
cifn 2.23292613
cifn 2.242699285
cifn 2.48409993
cifn 2.499756902
mdef 2.688390904
mdef 2.444735928
mdef 2.413170551
mdef 2.565289249
mdef 2.407801124
mdef 2.396522208
mdef 2.42247407
mdef 2.926033532
mdef 2.436730411
mdef 2.394851681
-----------------------------------------------------------
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
cifn 2.996028512
cifn 3.058455587
cifn 2.848704232
cifn 3.001133002
cifn 2.995359602
cifn 2.996879702
cifn 2.997351159
cifn 2.997235649
cifn 2.998638558
cifn 3.016651657
mdef 2.627404748
mdef 2.631601688
mdef 2.64632972
mdef 2.975902049
mdef 2.594292069
mdef 2.633122859
mdef 2.603393352
mdef 2.639759402
mdef 2.642814909
mdef 2.646872843
-----------------------------------------------------------
vm1_neq
i = 0
obj1 = Object.new
obj2 = Object.new
while i<30_000_000 # while loop 1
i += 1
obj1 != obj2
end
cifn 1.284488433
cifn 1.28732621
cifn 1.282232243
cifn 1.282379352
cifn 1.281899365
cifn 1.280746239
cifn 1.287106547
cifn 1.305795139
cifn 1.478182435
cifn 1.289774761
mdef 1.310601895
mdef 1.301249039
mdef 1.309961473
mdef 1.299846519
mdef 1.325417322
mdef 1.292311801
mdef 1.471985798
mdef 1.337527309
mdef 1.290874261
mdef 1.289897202
-----------------------------------------------------------
vm1_not
i = 0
obj = Object.new
while i<30_000_000 # while loop 1
i += 1
!obj
end
cifn 0.984429783
cifn 0.965685799
cifn 0.98092178
cifn 0.995185446
cifn 0.957895894
cifn 0.969292244
cifn 0.98229368
cifn 0.962963582
cifn 0.987625071
cifn 0.974927253
mdef 0.969220125
mdef 0.965695064
mdef 0.9606913
mdef 0.959484992
mdef 0.95440152
mdef 0.966044357
mdef 0.959280871
mdef 0.960810803
mdef 0.963681526
mdef 0.959028204
-----------------------------------------------------------
vm1_rescue
i = 0
while i<30_000_000 # while loop 1
i += 1
begin
rescue
end
end
cifn 0.809280415
cifn 0.814206293
cifn 0.812724023
cifn 0.814070325
cifn 0.819082854
cifn 0.822519891
cifn 0.813188535
cifn 0.813385092
cifn 0.809099377
cifn 0.807408569
mdef 0.805778767
mdef 0.807788475
mdef 0.811081237
mdef 0.803351008
mdef 0.802009463
mdef 0.806294018
mdef 0.810561658
mdef 0.813034008
mdef 0.801711384
mdef 0.798378882
-----------------------------------------------------------
vm1_simplereturn
def m
return 1
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m
end
cifn 1.655870822
cifn 1.656488219
cifn 1.741400057
cifn 1.651973753
cifn 1.656353644
cifn 1.726810614
cifn 1.664718789
cifn 1.6521749
cifn 1.681009831
cifn 1.656933713
mdef 1.740119404
mdef 1.649043316
mdef 1.642683516
mdef 1.647133343
mdef 1.660964934
mdef 1.649319881
mdef 1.64509474
mdef 1.646097496
mdef 1.645334658
mdef 1.647118091
-----------------------------------------------------------
vm1_swap
a = 1
b = 2
i = 0
while i<30_000_000 # while loop 1
i += 1
a, b = b, a
end
cifn 0.968673926
cifn 0.964921421
cifn 1.336021981
cifn 0.967274689
cifn 0.958431974
cifn 0.963001725
cifn 0.964357587
cifn 0.972340522
cifn 1.322859613
cifn 0.946647238
mdef 0.940318528
mdef 0.954040382
mdef 1.047975215
mdef 0.952092605
mdef 1.007755297
mdef 0.96034609
mdef 0.960023436
mdef 0.961940006
mdef 0.96460987
mdef 1.063193179
-----------------------------------------------------------
vm1_yield
def m
i = 0
while i<30_000_000 # while loop 1
i += 1
yield
end
end
m{}
cifn 1.636751377
cifn 1.746629904
cifn 1.606089028
cifn 1.597737755
cifn 1.612483966
cifn 1.606644849
cifn 1.612477066
cifn 1.606722492
cifn 1.603605519
cifn 1.599160022
mdef 1.619168182
mdef 1.590726035
mdef 1.594650595
mdef 1.602438061
mdef 1.598420277
mdef 1.617775792
mdef 1.603217252
mdef 1.616285157
mdef 1.601665226
mdef 1.607220424
-----------------------------------------------------------
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
cifn 1.178648643
cifn 1.187761579
cifn 1.176832361
cifn 1.189115083
cifn 1.186362881
cifn 1.187773819
cifn 1.18520834
cifn 1.255595692
cifn 1.173047732
cifn 1.188476684
mdef 1.191408292
mdef 1.217644284
mdef 1.191149652
mdef 1.175563723
mdef 1.177346494
mdef 1.164906804
mdef 1.206367053
mdef 1.182838288
mdef 1.222383916
mdef 1.213922661
-----------------------------------------------------------
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
cifn 12.311260975
cifn 12.318430254
cifn 12.57302298
cifn 12.282353696
cifn 12.249236138
cifn 12.100508207
cifn 12.601845119
cifn 12.409148987
cifn 12.444881929
cifn 11.383903617
mdef 12.174003627
mdef 12.310981826
mdef 12.233440501
mdef 12.18785811
mdef 12.189225059
mdef 12.023681984
mdef 13.250796917
mdef 12.298288968
mdef 12.418171211
mdef 12.265045339
-----------------------------------------------------------
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
cifn 7.248115767
cifn 7.201791631
cifn 7.216545129
cifn 7.212572499
cifn 7.287932481
cifn 7.180042265
cifn 7.345131478
cifn 7.264610438
cifn 7.397575905
cifn 7.155592974
mdef 7.175170444
mdef 7.314597973
mdef 7.108998568
mdef 7.211189893
mdef 7.309432486
mdef 7.291419249
mdef 7.16513238
mdef 7.179381585
mdef 7.284229254
mdef 7.7691465
-----------------------------------------------------------
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
cifn 0.283845597
cifn 0.284404002
cifn 0.281467228
cifn 0.335294545
cifn 0.282569952
cifn 0.281921044
cifn 0.279813692
cifn 0.279563797
cifn 0.302915195
cifn 0.2807327
mdef 0.280703638
mdef 0.284990038
mdef 0.284183861
mdef 0.286296464
mdef 0.280452924
mdef 0.289387475
mdef 0.281177955
mdef 0.289863239
mdef 0.280780034
mdef 0.281226066
-----------------------------------------------------------
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
cifn 3.822624635
cifn 3.419048838
cifn 3.369153444
cifn 3.439082617
cifn 3.450301346
cifn 3.453947272
cifn 3.38873971
cifn 3.478881313
cifn 3.438858535
cifn 3.525899061
mdef 3.616391232
mdef 3.489280673
mdef 3.497314274
mdef 3.456729293
mdef 3.560884522
mdef 3.433078866
mdef 3.42995745
mdef 3.407482415
mdef 3.45688279
mdef 3.457489809
-----------------------------------------------------------
vm2_dstr
i = 0
x = y = 'z'
while i<6_000_000 # benchmark loop 2
i += 1
str = "foo#{x}bar#{y}baz"
end
cifn 1.53281618
cifn 1.528217628
cifn 1.5893404
cifn 1.527445757
cifn 1.556382462
cifn 1.562417603
cifn 1.530526997
cifn 1.522969383
cifn 1.532390919
cifn 1.590073573
mdef 1.518141193
mdef 1.526078585
mdef 1.515984356
mdef 1.523030407
mdef 1.52828406
mdef 1.563616114
mdef 1.505017107
mdef 1.512043676
mdef 1.498741732
mdef 1.557591188
-----------------------------------------------------------
vm2_eval
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
eval("1")
end
cifn 24.753175554
cifn 26.039148847
cifn 24.192962643
cifn 27.700531376
cifn 27.943894005
cifn 25.410546374
cifn 25.504824699
cifn 28.103824074
cifn 24.667641087
cifn 26.223901585
mdef 26.037906535
mdef 25.573077056
mdef 25.734456869
mdef 26.14774226
mdef 25.678463447
mdef 25.739254547
mdef 23.882855634
mdef 25.150465246
mdef 26.126481206
mdef 25.034545123
-----------------------------------------------------------
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
cifn 1.754314184
cifn 1.707691462
cifn 1.993996364
cifn 1.790663844
cifn 1.71000027
cifn 1.761590451
cifn 1.767824413
cifn 1.71839877
cifn 1.841168285
cifn 1.722677194
mdef 1.727909306
mdef 1.727989559
mdef 1.727754274
mdef 1.722443217
mdef 1.908173946
mdef 1.745709562
mdef 1.743594149
mdef 1.785173694
mdef 1.870640209
mdef 1.736467794
-----------------------------------------------------------
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
cifn 2.570416247
cifn 2.601076886
cifn 2.56378403
cifn 2.80047649
cifn 2.592176455
cifn 2.654552644
cifn 2.595457276
cifn 2.717221712
cifn 2.619357304
cifn 2.58879263
mdef 2.693030123
mdef 2.773919249
mdef 2.783890115
mdef 2.57976323
mdef 2.703435814
mdef 2.643415682
mdef 3.064300412
mdef 2.830922211
mdef 2.581680799
mdef 2.578276909
-----------------------------------------------------------
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
cifn 1.922208847
cifn 1.923961502
cifn 1.985969189
cifn 2.113643174
cifn 1.925667384
cifn 1.971608077
cifn 1.927092241
cifn 1.929711296
cifn 1.930034415
cifn 1.918636879
mdef 1.91909179
mdef 1.926501499
mdef 2.061064192
mdef 1.910153688
mdef 2.021338056
mdef 1.913444589
mdef 2.1272288
mdef 1.956614671
mdef 1.944437835
mdef 1.922128174
-----------------------------------------------------------
vm2_mutex
require 'thread'
m = Mutex.new
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m.synchronize{}
end
cifn 1.083644946
cifn 1.023859427
cifn 1.006510017
cifn 1.021779169
cifn 1.036584682
cifn 1.02837573
cifn 1.035838481
cifn 0.997729715
cifn 1.045302436
cifn 1.143153382
mdef 1.010141764
mdef 1.001479192
mdef 1.004607013
mdef 0.99758676
mdef 1.029083378
mdef 1.018274731
mdef 1.023686456
mdef 0.998650354
mdef 1.025117253
mdef 0.999672167
-----------------------------------------------------------
vm2_newlambda
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
lambda {}
end
cifn 1.299795772
cifn 1.311144469
cifn 1.296135116
cifn 1.311141008
cifn 1.311250738
cifn 1.311278932
cifn 1.336762156
cifn 1.32181499
cifn 1.377689807
cifn 1.320601536
mdef 1.297381466
mdef 1.298053655
mdef 1.313563917
mdef 1.292104913
mdef 1.29802825
mdef 1.352514536
mdef 1.302636782
mdef 1.30826073
mdef 1.342523449
mdef 1.325722905
-----------------------------------------------------------
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
cifn 2.634414206
cifn 2.606027449
cifn 2.664044168
cifn 2.682163674
cifn 2.625508802
cifn 2.692110638
cifn 2.599998254
cifn 2.630046701
cifn 2.635553606
cifn 2.693964142
mdef 2.594745278
mdef 2.744647766
mdef 2.610970916
mdef 2.565963868
mdef 2.668710091
mdef 2.86349256
mdef 2.573478232
mdef 2.609872097
mdef 2.775970059
mdef 2.648622546
-----------------------------------------------------------
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
cifn 0.312799264
cifn 0.32951756
cifn 0.312485744
cifn 0.357810195
cifn 0.313458243
cifn 0.339689634
cifn 0.32391635
cifn 0.312266196
cifn 0.340640557
cifn 0.337264295
mdef 0.320172615
mdef 0.31313487
mdef 0.336966965
mdef 0.31263966
mdef 0.312239724
mdef 0.314349025
mdef 0.340941672
mdef 0.313415082
mdef 0.312729868
mdef 0.312741996
-----------------------------------------------------------
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
cifn 0.752354417
cifn 0.665795171
cifn 0.694479306
cifn 0.672977417
cifn 0.755849211
cifn 0.688817801
cifn 0.666014873
cifn 0.669833393
cifn 0.660956219
cifn 0.666778781
mdef 0.639916235
mdef 0.65927243
mdef 0.719953586
mdef 0.662151941
mdef 0.73498497
mdef 0.66543656
mdef 0.673490886
mdef 0.664127088
mdef 0.66566748
mdef 0.664823522
-----------------------------------------------------------
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
cifn 9.215497884
cifn 9.57104397
cifn 10.309303639
cifn 9.906103413
cifn 9.448375899
cifn 9.705883103
cifn 10.010231298
cifn 10.526139618
cifn 9.498940015
cifn 9.40117963
mdef 9.775538839
mdef 9.263316394
mdef 9.731311648
mdef 9.344758633
mdef 9.278072943
mdef 9.484409911
mdef 9.472244229
mdef 9.490061438
mdef 9.567101102
mdef 9.942514391
-----------------------------------------------------------
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
cifn 13.129221696
cifn 13.355182213
cifn 13.156104487
cifn 13.406784331
cifn 13.406773134
cifn 13.679979692
cifn 13.138345988
cifn 12.531916593
cifn 12.96893841
cifn 13.558001805
mdef 12.717346226
mdef 12.794548548
mdef 12.634394902
mdef 12.741303483
mdef 13.147971443
mdef 12.618554791
mdef 12.529625477
mdef 12.718741888
mdef 13.67542803
mdef 12.706459543
-----------------------------------------------------------
vm2_regexp
i = 0
str = 'xxxhogexxx'
while i<6_000_000 # benchmark loop 2
/hoge/ =~ str
i += 1
end
cifn 1.269724835
cifn 1.297211937
cifn 1.267210852
cifn 1.273459954
cifn 1.269004098
cifn 1.274748068
cifn 1.269492153
cifn 1.294472886
cifn 1.27155848
cifn 1.277408599
mdef 1.377293397
mdef 1.371240431
mdef 1.360391221
mdef 1.385120977
mdef 1.354930929
mdef 1.35629393
mdef 1.436953872
mdef 1.437980714
mdef 1.383172467
mdef 1.36719502
-----------------------------------------------------------
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
cifn 0.499700554
cifn 0.49849109
cifn 0.504663736
cifn 0.510690464
cifn 0.485899416
cifn 0.499458465
cifn 0.497726465
cifn 0.500349471
cifn 0.503963472
cifn 0.505067536
mdef 0.50958911
mdef 0.494297196
mdef 0.49940499
mdef 0.489419282
mdef 0.489467004
mdef 0.510208552
mdef 0.496409903
mdef 0.492308488
mdef 0.496010156
mdef 0.491825475
-----------------------------------------------------------
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
cifn 0.660771053
cifn 0.669921814
cifn 0.663856553
cifn 0.790579915
cifn 0.776376826
cifn 0.729198774
cifn 0.661399483
cifn 0.729618034
cifn 0.761447208
cifn 0.706276019
mdef 0.711887865
mdef 0.77349493
mdef 0.676411113
mdef 0.812367909
mdef 0.726931495
mdef 0.761123014
mdef 0.721395755
mdef 0.728087537
mdef 0.700079134
mdef 0.661766572
-----------------------------------------------------------
vm2_unif1
i = 0
def m a, b
end
while i<6_000_000 # benchmark loop 2
i += 1
m 100, 200
end
cifn 0.365474313
cifn 0.368770032
cifn 0.367663153
cifn 0.36872251
cifn 0.43064764
cifn 0.366879317
cifn 0.366576124
cifn 0.374174907
cifn 0.36699383
cifn 0.435726846
mdef 0.36370193
mdef 0.367996092
mdef 0.365440196
mdef 0.364873999
mdef 0.411611928
mdef 0.364673195
mdef 0.364277404
mdef 0.362094858
mdef 0.360100189
mdef 0.36444412
-----------------------------------------------------------
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
cifn 0.702999072
cifn 0.748582798
cifn 0.773785347
cifn 0.706988049
cifn 0.692175042
cifn 0.681998987
cifn 0.684018493
cifn 0.686581885
cifn 0.726866276
cifn 0.68725014
mdef 0.814276625
mdef 0.748831824
mdef 0.778657887
mdef 0.816450462
mdef 0.770271659
mdef 0.836708304
mdef 0.750405317
mdef 0.712491464
mdef 0.733560534
mdef 0.690036318
-----------------------------------------------------------
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
cifn 0.207521461
cifn 0.20794509
cifn 0.208727134
cifn 0.207227918
cifn 0.211767403
cifn 0.209253497
cifn 0.206898768
cifn 0.20791771
cifn 0.207393503
cifn 0.208442719
mdef 0.208081597
mdef 0.208672694
mdef 0.208489484
mdef 0.210288699
mdef 0.211932382
mdef 0.211268408
mdef 0.209268852
mdef 0.207482434
mdef 0.208704097
mdef 0.210654988
-----------------------------------------------------------
vm3_clearmethodcache
i = 0
while i<200_000
i += 1
Class.new{
def m; end
}
end
cifn 0.631744901
cifn 0.653191244
cifn 0.655167524
cifn 0.659739802
cifn 0.652567216
cifn 0.654100221
cifn 0.669359194
cifn 0.653969403
cifn 0.653946751
cifn 0.661734264
mdef 0.653567879
mdef 0.650679996
mdef 0.653816937
mdef 0.648584065
mdef 0.659134344
mdef 0.652117168
mdef 0.654277331
mdef 0.649907494
mdef 0.659785917
mdef 0.667351305
-----------------------------------------------------------
vm3_gc
#! /usr/bin/ruby
5000.times do
100.times do
{"xxxx"=>"yyyy"}
end
GC.start
end
cifn 3.331856056
cifn 3.294262381
cifn 3.303748793
cifn 3.310731068
cifn 3.300816554
cifn 3.317258536
cifn 3.330515704
cifn 3.314967823
cifn 3.308162246
cifn 3.29491037
mdef 3.217641305
mdef 3.225678175
mdef 3.220817372
mdef 3.245372765
mdef 3.261161381
mdef 3.233930392
mdef 3.216360773
mdef 3.253523252
mdef 3.218010299
mdef 3.226351902
-----------------------------------------------------------
vm_thread_alive_check1
5_000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}
cifn 0.178672019
cifn 0.181572572
cifn 0.172708596
cifn 0.184592114
cifn 0.179506919
cifn 0.178976646
cifn 0.187692113
cifn 0.177371923
cifn 0.177176055
cifn 0.178438211
mdef 0.178092755
mdef 0.178182567
mdef 0.181413884
mdef 0.179464203
mdef 0.182637721
mdef 0.179071936
mdef 0.186649433
mdef 0.179567382
mdef 0.178684154
mdef 0.177699716
-----------------------------------------------------------
vm_thread_close
1000.times { Thread.new { sleep } }
i = 0
while i<100_000 # benchmark loop 3
i += 1
IO.pipe.each(&:close)
end
cifn 3.897032509
cifn 3.849946839
cifn 4.032078046
cifn 3.97707177
cifn 3.832827513
cifn 3.954734503
cifn 3.924628298
cifn 4.012823461
cifn 3.986265333
cifn 3.840659427
mdef 3.506260682
mdef 3.980909245
mdef 3.982780129
mdef 3.867179995
mdef 3.918161811
mdef 4.026997169
mdef 3.978415964
mdef 3.906168385
mdef 3.9148788
mdef 3.985851046
-----------------------------------------------------------
vm_thread_create_join
i = 0
while i<100_000 # benchmark loop 3
i += 1
Thread.new{
}.join
end
cifn 2.481305353
cifn 2.518963734
cifn 2.413755421
cifn 2.501034909
cifn 2.404519806
cifn 2.411280138
cifn 2.340603182
cifn 2.505544551
cifn 2.443927093
cifn 2.506702895
mdef 2.52598272
mdef 2.495050825
mdef 2.49543427
mdef 2.524002219
mdef 2.499759661
mdef 2.270244192
mdef 2.290634309
mdef 2.380817086
mdef 2.359349913
mdef 2.430167873
-----------------------------------------------------------
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