2014-09-20 00:09:01 +0000
target 0: orig (ruby 2.2.0dev (2014-09-19 trunk 47642) [x86_64-linux]) at "./gcc/ruby.orig"
target 1: cifn (ruby 2.2.0dev (2014-09-19 trunk 47642) [x86_64-linux]) at "./gcc/ruby.cifn"
-----------------------------------------------------------
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
orig 0.078151178
orig 0.072785051
orig 0.078860205
orig 0.072265991
orig 0.073143796
orig 0.072851641
orig 0.07243626
orig 0.080157292
orig 0.074011964
orig 0.075470518
cifn 0.078892294
cifn 0.082564389
cifn 0.078675454
cifn 0.078840275
cifn 0.073395115
cifn 0.078297912
cifn 0.073329443
cifn 0.078010461
cifn 0.07844699
cifn 0.078092596
-----------------------------------------------------------
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
orig 74.858332016
orig 72.541863573
orig 73.628666378
orig 73.705998547
orig 75.478112835
orig 73.90361499
orig 73.717157085
orig 73.789863217
orig 73.550603578
orig 73.275610339
cifn 76.52190147
cifn 77.216023053
cifn 77.314444098
cifn 76.116173493
cifn 77.159462974
cifn 77.258483781
cifn 76.348364203
cifn 75.887208067
cifn 76.926768117
cifn 74.98884681
-----------------------------------------------------------
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 %>
orig 1.414355109
orig 1.414033751
orig 1.4140209
orig 1.416326044
orig 1.495176058
orig 1.412798444
orig 1.416701808
orig 1.414982055
orig 1.411759521
orig 1.417618979
cifn 1.393574323
cifn 1.405622127
cifn 1.475398635
cifn 1.405222237
cifn 1.402940494
cifn 1.456542626
cifn 1.396507549
cifn 1.402835662
cifn 1.396807109
cifn 1.398078882
-----------------------------------------------------------
app_factorial
def fact(n)
if(n > 1)
n * fact(n-1)
else
1
end
end
100.times {
fact(5000)
}
orig 1.182035236
orig 1.180783653
orig 1.180854957
orig 1.180206179
orig 1.182696559
orig 1.178741527
orig 1.180066759
orig 1.180315947
orig 1.185476293
orig 1.180300142
cifn 1.175088041
cifn 1.175419308
cifn 1.17773414
cifn 1.18005175
cifn 1.178646844
cifn 1.17915303
cifn 1.17585955
cifn 1.184532829
cifn 1.17060244
cifn 1.176566951
-----------------------------------------------------------
app_fib
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)
orig 0.731810835
orig 0.675856474
orig 0.701844393
orig 0.715324436
orig 0.74663241
orig 0.71589092
orig 0.677667266
orig 0.694987864
orig 0.754766137
orig 0.688349831
cifn 0.73352256
cifn 0.757586191
cifn 0.690186136
cifn 0.702180417
cifn 0.746339823
cifn 0.706666727
cifn 0.681853998
cifn 0.757415861
cifn 0.714174514
cifn 0.789012324
-----------------------------------------------------------
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
orig 99.575140229
orig 96.728095764
orig 98.974337455
orig 96.884842591
orig 97.789529684
orig 96.967345551
orig 100.998503395
orig 99.961028473
orig 99.644362589
orig 96.65384932
cifn 97.050575292
cifn 92.922380466
cifn 92.229969948
cifn 93.304104963
cifn 96.868317475
cifn 95.30359556
cifn 91.447027412
cifn 93.530283607
cifn 95.058196332
cifn 92.949289838
-----------------------------------------------------------
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)
}
}
orig 1.394353436
orig 1.368277742
orig 1.401984682
orig 1.40659426
orig 1.440783369
orig 1.411469115
orig 1.426823032
orig 1.423902275
orig 1.445222162
orig 1.41392112
cifn 1.47088585
cifn 1.433316521
cifn 1.45597583
cifn 1.464619881
cifn 1.471516799
cifn 1.490426093
cifn 1.474278035
cifn 1.561282024
cifn 1.468351653
cifn 1.45265951
-----------------------------------------------------------
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)
orig 19.342161238
orig 19.861899666
orig 19.280083007
orig 19.9286452
orig 19.675654746
orig 19.463186976
orig 18.938627014
orig 19.919312131
orig 19.197756211
orig 19.864311646
cifn 19.853050624
cifn 19.847447908
cifn 19.382305581
cifn 19.953931586
cifn 19.540314511
cifn 19.735616723
cifn 19.940303535
cifn 19.917388373
cifn 19.562206375
cifn 20.263384349
-----------------------------------------------------------
app_raise
i = 0
while i<300000
i += 1
begin
raise
rescue
end
end
orig 0.444829743
orig 0.450192238
orig 0.446680893
orig 0.450511551
orig 0.437802188
orig 0.445510578
orig 0.451176665
orig 0.452942579
orig 0.446226356
orig 0.446436639
cifn 0.45289781
cifn 0.485157982
cifn 0.478024288
cifn 0.467600943
cifn 0.46528659
cifn 0.468684868
cifn 0.489686797
cifn 0.465900007
cifn 0.471010467
cifn 0.484670535
-----------------------------------------------------------
app_strconcat
i = 0
while i<2_000_000
"#{1+1} #{1+1} #{1+1}"
i += 1
end
orig 1.115194568
orig 1.119935968
orig 1.112029791
orig 1.13677995
orig 1.114357054
orig 1.108762007
orig 1.110157265
orig 1.172762994
orig 1.114133139
orig 1.126499933
cifn 1.160116391
cifn 1.150152103
cifn 1.16152586
cifn 1.160256185
cifn 1.149141067
cifn 1.179062629
cifn 1.146923744
cifn 1.146760439
cifn 1.170180083
cifn 1.164884799
-----------------------------------------------------------
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)
orig 0.915182867
orig 0.92099591
orig 0.912280237
orig 0.922582023
orig 0.939950007
orig 0.914317836
orig 0.911502434
orig 0.931384973
orig 0.946365082
orig 1.017065368
cifn 0.960522683
cifn 0.924191348
cifn 0.91415265
cifn 1.079204961
cifn 0.925815822
cifn 1.109778678
cifn 1.06227267
cifn 1.045489878
cifn 0.931275874
cifn 0.992360207
-----------------------------------------------------------
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)
orig 0.816906834
orig 0.74207103
orig 0.792217913
orig 0.782800373
orig 0.737863129
orig 0.764843454
orig 0.778556393
orig 0.793004665
orig 0.764626288
orig 0.739018694
cifn 0.907125385
cifn 0.766139078
cifn 0.769343473
cifn 0.975300151
cifn 0.731609291
cifn 0.889896736
cifn 0.773030644
cifn 0.780642622
cifn 0.735091166
cifn 0.849782886
-----------------------------------------------------------
app_uri
require 'uri'
100_000.times{
uri = URI.parse('http://www.ruby-lang.org')
uri.scheme
uri.host
uri.port
}
orig 1.190712864
orig 1.199307637
orig 1.188462342
orig 1.189586224
orig 1.216327381
orig 1.289552257
orig 1.191543462
orig 1.185000968
orig 1.185666794
orig 1.190004273
cifn 1.199149248
cifn 1.215982494
cifn 1.203610905
cifn 1.271079517
cifn 1.200696104
cifn 1.203083511
cifn 1.211527574
cifn 1.196882119
cifn 1.17623621
cifn 1.199912829
-----------------------------------------------------------
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] } }
orig 0.530029202
orig 0.552855419
orig 0.541749145
orig 0.543437601
orig 0.533043197
orig 0.551523375
orig 0.536812515
orig 0.55534164
orig 0.560127287
orig 0.547769787
cifn 0.571509651
cifn 0.562780653
cifn 0.563919007
cifn 0.558989529
cifn 0.57594545
cifn 0.562016784
cifn 0.569183006
cifn 0.562886622
cifn 0.557906063
cifn 0.571064365
-----------------------------------------------------------
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] } }
orig 0.510340207
orig 0.514479416
orig 0.516884718
orig 0.506173893
orig 0.495759744
orig 0.503120848
orig 0.509437828
orig 0.500631444
orig 0.549416528
orig 0.527873137
cifn 0.539453106
cifn 0.545334117
cifn 0.53007819
cifn 0.549939305
cifn 0.525328043
cifn 0.536765493
cifn 0.535325878
cifn 0.523604159
cifn 0.538761087
cifn 0.536634314
-----------------------------------------------------------
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] } }
orig 0.732356706
orig 0.74358441
orig 0.774500441
orig 0.785101042
orig 0.783940903
orig 0.764741438
orig 0.774012248
orig 0.757432982
orig 0.757056091
orig 0.767295612
cifn 0.761590456
cifn 0.76121874
cifn 0.749500543
cifn 0.77620265
cifn 0.766410507
cifn 0.782303258
cifn 0.780658032
cifn 0.757724678
cifn 0.747459884
cifn 0.744310718
-----------------------------------------------------------
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] } }
orig 1.942826879
orig 1.626362606
orig 1.675354406
orig 1.668960554
orig 1.687193915
orig 1.817079817
orig 1.647772115
orig 1.63081049
orig 1.692607558
orig 1.681319186
cifn 1.76967076
cifn 1.636154841
cifn 1.784168338
cifn 1.69885475
cifn 1.675119614
cifn 1.659233509
cifn 1.708296684
cifn 1.649934899
cifn 1.652248239
cifn 1.71676007
-----------------------------------------------------------
hash_flatten
h = {}
10000.times do |i|
h[i] = nil
end
1000.times do
h.flatten
end
orig 0.657202361
orig 0.658377088
orig 0.658220448
orig 0.659708571
orig 0.661240437
orig 0.663067362
orig 0.668377948
orig 0.659140827
orig 0.66103176
orig 0.656491288
cifn 0.649227913
cifn 0.653141099
cifn 0.645580784
cifn 0.644912529
cifn 0.645682467
cifn 0.651332223
cifn 0.648546763
cifn 0.649322532
cifn 0.650309911
cifn 0.646289122
-----------------------------------------------------------
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] } }
orig 0.370775125
orig 0.372802943
orig 0.406969517
orig 0.371817636
orig 0.365161971
orig 0.384015605
orig 0.373731973
orig 0.401852017
orig 0.367102039
orig 0.3986088
cifn 0.40882485
cifn 0.411144576
cifn 0.398628612
cifn 0.396523691
cifn 0.408966764
cifn 0.413472739
cifn 0.427444135
cifn 0.407025612
cifn 0.392909091
cifn 0.391321939
-----------------------------------------------------------
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] } }
orig 0.37256343
orig 0.363841122
orig 0.362821156
orig 0.364282501
orig 0.38658887
orig 0.368298059
orig 0.364547789
orig 0.371131418
orig 0.382408068
orig 0.366312797
cifn 0.395241977
cifn 0.503141132
cifn 0.408624293
cifn 0.390482327
cifn 0.39002472
cifn 0.388463973
cifn 0.389232366
cifn 0.387417607
cifn 0.39848817
cifn 0.387849725
-----------------------------------------------------------
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] } }
orig 0.364458999
orig 0.365402846
orig 0.383306223
orig 0.383145868
orig 0.364425677
orig 0.365953144
orig 0.374193902
orig 0.368898149
orig 0.361635309
orig 0.362933404
cifn 0.38853026
cifn 0.396875424
cifn 0.400680721
cifn 0.38845363
cifn 0.39861149
cifn 0.398302294
cifn 0.405617244
cifn 0.392632852
cifn 0.403139099
cifn 0.394844621
-----------------------------------------------------------
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] } }
orig 0.383008475
orig 0.417029474
orig 0.405151893
orig 0.407678191
orig 0.390390892
orig 0.394604849
orig 0.382913614
orig 0.387774971
orig 0.406310476
orig 0.406480803
cifn 0.447279504
cifn 0.428712778
cifn 0.414847729
cifn 0.424616173
cifn 0.433761736
cifn 0.418151153
cifn 0.42317865
cifn 0.440306071
cifn 0.438848937
cifn 0.452678025
-----------------------------------------------------------
hash_keys
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.keys
end
orig 0.262306734
orig 0.262859467
orig 0.26010753
orig 0.261202353
orig 0.260146712
orig 0.262804875
orig 0.262704985
orig 0.262712444
orig 0.262508408
orig 0.26000175
cifn 0.260578447
cifn 0.261408927
cifn 0.263649359
cifn 0.259965315
cifn 0.263374286
cifn 0.265087357
cifn 0.259943165
cifn 0.263238243
cifn 0.261406559
cifn 0.26399876
-----------------------------------------------------------
hash_shift
h = {}
10000.times do |i|
h[i] = nil
end
50000.times do
k, v = h.shift
h[k] = v
end
orig 0.053633821
orig 0.053528609
orig 0.052757011
orig 0.053873792
orig 0.052962005
orig 0.053452894
orig 0.053104938
orig 0.053527079
orig 0.052716649
orig 0.053718942
cifn 0.053162504
cifn 0.053071708
cifn 0.054443338
cifn 0.053881601
cifn 0.053887242
cifn 0.053117381
cifn 0.054056343
cifn 0.052962048
cifn 0.054752226
cifn 0.05266881
-----------------------------------------------------------
hash_values
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.values
end
orig 0.276105549
orig 0.267915954
orig 0.274720385
orig 0.267521878
orig 0.274961358
orig 0.267943851
orig 0.26874393
orig 0.275603995
orig 0.276430487
orig 0.274256648
cifn 0.283599529
cifn 0.281791894
cifn 0.274884207
cifn 0.281939
cifn 0.275057256
cifn 0.275062344
cifn 0.282198733
cifn 0.282877353
cifn 0.282872526
cifn 0.280956793
-----------------------------------------------------------
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)
orig 2.103958514
orig 2.078021149
orig 2.277861968
orig 2.100775486
orig 2.134107152
orig 2.090856474
orig 2.113006959
orig 2.26448501
orig 2.091263119
orig 2.264098731
cifn 2.086481074
cifn 2.271116782
cifn 2.075887538
cifn 2.236192639
cifn 2.07763154
cifn 2.080639188
cifn 2.083033621
cifn 2.091335023
cifn 2.098171999
cifn 2.05539035
-----------------------------------------------------------
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
}
orig 2.569359591
orig 2.404257165
orig 2.395881139
orig 2.406258572
orig 2.407008552
orig 2.402461752
orig 2.377123707
orig 2.395571017
orig 2.394764627
orig 2.39909728
cifn 2.398578148
cifn 2.397560086
cifn 2.393845353
cifn 2.393465507
cifn 2.39227035
cifn 2.391938205
cifn 2.379045335
cifn 2.39107934
cifn 2.393002032
cifn 2.42063097
-----------------------------------------------------------
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
}
orig 1.401515345
orig 1.570079196
orig 1.452862693
orig 1.434654481
orig 1.435617071
orig 1.599964596
orig 1.427442368
orig 1.429640767
orig 1.607244719
orig 1.416902562
cifn 1.387008631
cifn 1.405284039
cifn 1.570598355
cifn 1.395409773
cifn 1.388862735
cifn 1.541965627
cifn 1.456091098
cifn 1.384891773
cifn 1.461917847
cifn 1.390665074
-----------------------------------------------------------
io_select
# IO.select performance
w = [ IO.pipe[1] ];
nr = 1000000
nr.times {
IO.select nil, w
}
orig 2.217756413
orig 2.249775132
orig 2.220331399
orig 2.232176472
orig 2.253835053
orig 2.286778371
orig 2.259242248
orig 2.278398183
orig 2.278762076
orig 2.259906711
cifn 2.200032662
cifn 2.225395537
cifn 2.294022432
cifn 2.207920514
cifn 2.223797404
cifn 2.21259566
cifn 2.225816487
cifn 2.204038512
cifn 2.156927786
cifn 2.195052938
-----------------------------------------------------------
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
orig 2.575626905
orig 2.571479236
orig 2.519194265
orig 2.557600059
orig 2.591533159
orig 2.571859093
orig 2.58872112
orig 2.560045002
orig 2.600701439
orig 2.590261683
cifn 2.651337945
cifn 2.565041653
cifn 2.592682879
cifn 2.582545271
cifn 2.579011881
cifn 2.586772008
cifn 2.604890094
cifn 2.555964808
cifn 2.597872286
cifn 2.595246695
-----------------------------------------------------------
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
orig 0.054407386
orig 0.054169497
orig 0.054984735
orig 0.05469245
orig 0.055573757
orig 0.054321174
orig 0.054452904
orig 0.054508879
orig 0.05441016
orig 0.054356427
cifn 0.053893817
cifn 0.054118404
cifn 0.054014914
cifn 0.054192716
cifn 0.054384784
cifn 0.055385655
cifn 0.054567357
cifn 0.054108115
cifn 0.054267563
cifn 0.05396737
-----------------------------------------------------------
loop_for
for i in 1..30_000_000
#
end
orig 1.447215626
orig 1.401623462
orig 1.395873884
orig 1.398121895
orig 1.403701045
orig 1.372668031
orig 1.385453794
orig 1.42527918
orig 1.383154937
orig 1.394410514
cifn 1.533842517
cifn 1.535260723
cifn 1.534553057
cifn 1.59116451
cifn 1.528605186
cifn 1.525993725
cifn 1.568165115
cifn 1.494391275
cifn 1.538599573
cifn 1.537140512
-----------------------------------------------------------
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
orig 1.106630914
orig 1.098601724
orig 1.108863139
orig 1.109337787
orig 1.104748564
orig 1.10344222
orig 1.081784428
orig 1.111475497
orig 1.098351669
orig 1.105761872
cifn 1.096164235
cifn 1.087360675
cifn 1.078349017
cifn 1.119043335
cifn 1.085157687
cifn 1.071493777
cifn 1.089965722
cifn 1.086771115
cifn 1.086074865
cifn 1.096309235
-----------------------------------------------------------
loop_times
30_000_000.times{|e|}
orig 1.285553977
orig 1.296427209
orig 1.302573338
orig 1.293318306
orig 1.300368701
orig 1.300572084
orig 1.29922296
orig 1.29811362
orig 1.300685853
orig 1.291875607
cifn 1.480121245
cifn 1.420226047
cifn 1.419252532
cifn 1.389415805
cifn 1.491622224
cifn 1.420764659
cifn 1.436620782
cifn 1.422151776
cifn 1.396458376
cifn 1.405517891
-----------------------------------------------------------
loop_whileloop
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
end
orig 0.672092149
orig 0.675662277
orig 0.674653608
orig 0.673744472
orig 0.67529675
orig 0.67408227
orig 0.675801986
orig 0.673607392
orig 0.673577963
orig 0.672179352
cifn 0.677233669
cifn 0.678358015
cifn 0.679212863
cifn 0.68637926
cifn 0.679297128
cifn 0.679503004
cifn 0.681585793
cifn 0.681949052
cifn 0.681333754
cifn 0.683018238
-----------------------------------------------------------
loop_whileloop2
i = 0
while i< 6_000_000 # benchmark loop 2
i += 1
end
orig 0.157892254
orig 0.157862796
orig 0.157898067
orig 0.157704376
orig 0.157930482
orig 0.157603773
orig 0.158103202
orig 0.157943321
orig 0.157578142
orig 0.15779115
cifn 0.160216894
cifn 0.159905862
cifn 0.159541879
cifn 0.158906129
cifn 0.159172467
cifn 0.159361145
cifn 0.159577951
cifn 0.158600602
cifn 0.158878847
cifn 0.159220069
-----------------------------------------------------------
securerandom
require "securerandom"
20_0000.times do
SecureRandom.random_number(100)
end
orig 0.988539129
orig 1.000133661
orig 1.03845116
orig 1.003778771
orig 0.985949572
orig 0.999144915
orig 0.986988513
orig 0.995430578
orig 0.976358399
orig 1.024420551
cifn 1.061652553
cifn 1.05245536
cifn 1.023429606
cifn 1.034321921
cifn 1.040933395
cifn 1.041147367
cifn 1.046684707
cifn 1.023671178
cifn 1.059645015
cifn 1.023029293
-----------------------------------------------------------
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)
orig 0.719268886
orig 0.72357559
orig 0.741555683
orig 0.778118817
orig 0.722090126
orig 0.787598356
orig 0.723344047
orig 0.72517646
orig 0.722117773
orig 0.847546453
cifn 0.793603263
cifn 0.8142818
cifn 0.804350454
cifn 0.720551692
cifn 0.868823752
cifn 0.798116002
cifn 0.797215035
cifn 0.726923645
cifn 0.734700864
cifn 0.831318323
-----------------------------------------------------------
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}"
orig 1.005188675
orig 0.989696565
orig 0.993322493
orig 0.930884464
orig 0.929207768
orig 0.922396448
orig 0.965833184
orig 0.993870862
orig 0.994235704
orig 0.96696356
cifn 0.996072591
cifn 1.017795618
cifn 0.981382558
cifn 0.994745333
cifn 0.977379771
cifn 0.97899864
cifn 0.968220251
cifn 0.96472501
cifn 0.970520296
cifn 0.96408515
-----------------------------------------------------------
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
orig 7.890381164
orig 7.901066805
orig 7.840817312
orig 7.82221436
orig 7.903816011
orig 7.868983201
orig 7.697092585
orig 7.837809935
orig 7.950685408
orig 8.008511227
cifn 7.832206933
cifn 8.043556257
cifn 7.788224577
cifn 7.802032653
cifn 7.753556137
cifn 7.873353418
cifn 8.043624812
cifn 7.974982026
cifn 7.821274816
cifn 7.699206376
-----------------------------------------------------------
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
orig 3.673168509
orig 3.662537098
orig 3.575836826
orig 3.656948184
orig 3.581877306
orig 3.741390337
orig 3.599009684
orig 3.603695647
orig 3.602693783
orig 3.595399029
cifn 3.866951938
cifn 3.874113575
cifn 3.858025149
cifn 3.866985106
cifn 3.845955714
cifn 3.893832409
cifn 3.887667719
cifn 3.899749914
cifn 3.989927629
cifn 3.909038573
-----------------------------------------------------------
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}"
orig 0.290493201
orig 0.291544736
orig 0.288626963
orig 0.288688317
orig 0.288648039
orig 0.288535465
orig 0.288737794
orig 0.289718001
orig 0.288317913
orig 0.291091945
cifn 0.305044982
cifn 0.305258927
cifn 0.304762725
cifn 0.307683928
cifn 0.306378323
cifn 0.305539752
cifn 0.305819489
cifn 0.30567236
cifn 0.306654039
cifn 0.307968903
-----------------------------------------------------------
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
orig 0.45233566
orig 0.465649967
orig 0.470494314
orig 0.475135973
orig 0.484375104
orig 0.512305505
orig 0.469157372
orig 0.463536439
orig 0.4861248
orig 0.451729016
cifn 0.509004818
cifn 0.517074363
cifn 0.515689627
cifn 0.530406195
cifn 0.540644839
cifn 0.510019583
cifn 0.499663341
cifn 0.513070809
cifn 0.504727105
cifn 0.514197213
-----------------------------------------------------------
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)}"
orig 1.745337946
orig 1.724664619
orig 1.71727652
orig 1.770308686
orig 1.715681028
orig 1.713537165
orig 1.734117152
orig 1.717084415
orig 1.715816925
orig 1.709842978
cifn 1.752432647
cifn 1.726085977
cifn 1.720781618
cifn 1.759445059
cifn 1.773389004
cifn 1.720518349
cifn 1.750692433
cifn 1.732018789
cifn 1.733217287
cifn 1.745136106
-----------------------------------------------------------
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)
orig 2.330657572
orig 2.248991508
orig 2.316411642
orig 2.326898959
orig 2.260194814
orig 2.257732544
orig 2.326031708
orig 2.317452377
orig 2.313225317
orig 2.304931192
cifn 2.439059185
cifn 2.401838735
cifn 2.379715074
cifn 2.410313056
cifn 2.377327258
cifn 2.38042778
cifn 2.434434461
cifn 2.409849624
cifn 2.453546964
cifn 2.453265708
-----------------------------------------------------------
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) }
orig 1.216993286
orig 1.229179677
orig 1.23668187
orig 1.232962133
orig 1.241905833
orig 1.241573446
orig 1.250305322
orig 1.234350985
orig 1.241616227
orig 1.229153758
cifn 1.195904736
cifn 1.210479555
cifn 1.222108896
cifn 1.2013466
cifn 1.188467201
cifn 1.213580507
cifn 1.203868341
cifn 1.200967701
cifn 1.194746844
cifn 1.20158466
-----------------------------------------------------------
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
orig 3.023870834
orig 3.087457721
orig 3.113774474
orig 3.109307068
orig 3.154172794
orig 3.056144217
orig 3.101195273
orig 3.015900341
orig 3.253877053
orig 3.170038286
cifn 3.139668786
cifn 3.174309281
cifn 3.2129818
cifn 3.211495527
cifn 3.657384796
cifn 3.07439072
cifn 3.071402656
cifn 3.143619972
cifn 3.097553697
cifn 3.424409937
-----------------------------------------------------------
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]}"
orig 0.713262605
orig 0.708080576
orig 0.728113796
orig 0.756019935
orig 0.741782465
orig 0.695590785
orig 0.766977583
orig 0.720424342
orig 0.743265467
orig 0.711248709
cifn 0.751371203
cifn 0.758821976
cifn 0.772010486
cifn 0.768235494
cifn 0.772149486
cifn 0.754675688
cifn 0.752126344
cifn 0.792190728
cifn 0.743410748
cifn 0.751876522
-----------------------------------------------------------
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!!!
orig 3.67114085
orig 3.593961398
orig 3.826274447
orig 3.79538159
orig 3.83525999
orig 3.61737035
orig 3.822508736
orig 3.85352548
orig 3.843574506
orig 3.813140417
cifn 3.878399896
cifn 3.681479941
cifn 3.961757887
cifn 3.898466858
cifn 3.680795259
cifn 3.707835965
cifn 3.650970398
cifn 3.710281272
cifn 3.876296235
cifn 3.678050197
-----------------------------------------------------------
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)
orig 1.86271044
orig 1.913292826
orig 1.894710762
orig 1.946157906
orig 1.857910943
orig 1.8803378
orig 1.96309783
orig 1.858924936
orig 1.901960947
orig 1.883437911
cifn 1.915053532
cifn 1.895105928
cifn 1.849165827
cifn 1.856526716
cifn 1.966446593
cifn 1.874265355
cifn 1.835258921
cifn 1.865833104
cifn 1.901435987
cifn 1.903023682
-----------------------------------------------------------
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
orig 1.168206525
orig 1.167264132
orig 1.152494443
orig 1.155745227
orig 1.190495539
orig 1.173008637
orig 1.204785218
orig 1.162134955
orig 1.168602441
orig 1.179134698
cifn 1.27763003
cifn 1.261080771
cifn 1.27165656
cifn 1.255172897
cifn 1.263978746
cifn 1.289235334
cifn 1.246910323
cifn 1.254173836
cifn 1.272317025
cifn 1.268527783
-----------------------------------------------------------
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
orig 2.396880121
orig 2.366058836
orig 2.337704745
orig 2.361891152
orig 2.699182455
orig 2.317660809
orig 2.626198148
orig 2.367413228
orig 2.326585369
orig 2.368311927
cifn 2.387398976
cifn 2.356968089
cifn 2.379639341
cifn 2.394075283
cifn 2.349304438
cifn 2.37399347
cifn 2.455276972
cifn 2.502772053
cifn 2.370199414
cifn 2.459216328
-----------------------------------------------------------
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
orig 2.345462181
orig 2.349537161
orig 2.297819972
orig 2.389569126
orig 2.334279395
orig 2.381378265
orig 2.38918591
orig 2.392061613
orig 2.400252814
orig 2.313409158
cifn 2.369802787
cifn 2.405850342
cifn 2.436002832
cifn 2.37685863
cifn 2.417361968
cifn 2.416446242
cifn 2.446902256
cifn 2.494000496
cifn 2.479759034
cifn 2.507764493
-----------------------------------------------------------
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
orig 0.775721666
orig 0.839933792
orig 0.799973609
orig 0.7708415
orig 0.788590798
orig 0.775848016
orig 0.784226634
orig 0.797112123
orig 0.775663358
orig 0.77432259
cifn 0.803966458
cifn 0.805236442
cifn 0.771514365
cifn 0.788963668
cifn 0.795231161
cifn 0.799137838
cifn 0.783101171
cifn 0.789063446
cifn 0.787435172
cifn 0.78646947
-----------------------------------------------------------
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
orig 2.878479836
orig 2.758377071
orig 2.813461626
orig 2.862676848
orig 2.878041152
orig 2.864024283
orig 2.797073848
orig 2.843159958
orig 2.781949103
orig 2.732944605
cifn 2.918601498
cifn 2.903406819
cifn 2.914244377
cifn 2.871870311
cifn 2.776542593
cifn 2.821453384
cifn 2.844797721
cifn 2.867530677
cifn 2.913645333
cifn 2.921881173
-----------------------------------------------------------
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
orig 1.256943279
orig 1.273233841
orig 1.256598404
orig 1.260801676
orig 1.265198445
orig 1.26758031
orig 1.266032779
orig 1.261461174
orig 1.264543727
orig 1.279940041
cifn 1.26364627
cifn 1.255159783
cifn 1.264779498
cifn 1.25882586
cifn 1.256652324
cifn 1.259997643
cifn 1.264958927
cifn 1.232413701
cifn 1.256123961
cifn 1.266354834
-----------------------------------------------------------
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)
orig 1.745493635
orig 1.746351574
orig 1.620375707
orig 1.61912337
orig 1.627531084
orig 1.735772205
orig 1.754886945
orig 1.655209587
orig 1.744107069
orig 1.739973987
cifn 1.739539593
cifn 1.74357632
cifn 1.742680953
cifn 1.746426359
cifn 1.751110052
cifn 1.753559264
cifn 1.735270829
cifn 1.72650177
cifn 1.753172901
cifn 1.638206825
-----------------------------------------------------------
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
orig 0.63554094
orig 0.673408207
orig 0.653674384
orig 0.666293179
orig 0.659302018
orig 0.733054255
orig 0.652330797
orig 0.651843029
orig 0.653747117
orig 0.673193517
cifn 0.645917054
cifn 0.66108928
cifn 0.660698058
cifn 0.643978253
cifn 0.642191288
cifn 0.659659284
cifn 0.657794173
cifn 0.656809124
cifn 0.649071847
cifn 0.677405216
-----------------------------------------------------------
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
orig 2.275585508
orig 2.269779035
orig 2.239357723
orig 2.317901546
orig 2.308938123
orig 2.273126652
orig 2.215545643
orig 2.227141036
orig 2.255796428
orig 2.244168931
cifn 2.47458012
cifn 2.449790635
cifn 2.384270973
cifn 2.60409981
cifn 2.444421155
cifn 2.343669428
cifn 2.437996013
cifn 2.470538988
cifn 2.439739448
cifn 2.449940767
-----------------------------------------------------------
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
orig 1.751137014
orig 1.809193196
orig 1.793956783
orig 1.683983131
orig 1.730337612
orig 1.82841845
orig 1.755854668
orig 1.760619478
orig 1.676930537
orig 1.885927609
cifn 1.82354127
cifn 1.768817311
cifn 1.820647624
cifn 1.795659624
cifn 1.781852345
cifn 1.813258602
cifn 1.78727982
cifn 1.77049819
cifn 1.777558412
cifn 1.834639973
-----------------------------------------------------------
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
orig 2.13909704
orig 2.09278718
orig 2.09036428
orig 2.398596188
orig 2.083683066
orig 2.050450821
orig 2.391229706
orig 2.182338635
orig 2.218711006
orig 2.301912374
cifn 1.976035052
cifn 2.116950522
cifn 2.026584015
cifn 1.917734227
cifn 2.316345687
cifn 1.969687887
cifn 1.994609216
cifn 2.007454125
cifn 2.021941704
cifn 2.070568469
-----------------------------------------------------------
vm1_block
def m
yield
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m{
}
end
orig 2.89983856
orig 2.575503049
orig 2.632698469
orig 2.573205764
orig 2.580549964
orig 2.799282993
orig 2.890492523
orig 2.702887782
orig 2.604283301
orig 2.677848568
cifn 3.373754249
cifn 2.702368884
cifn 2.621827012
cifn 2.631367467
cifn 2.627513503
cifn 2.733133981
cifn 2.831765442
cifn 2.631306356
cifn 2.632959056
cifn 2.598673755
-----------------------------------------------------------
vm1_const
Const = 1
i = 0
while i<30_000_000 # while loop 1
i += 1
j = Const
k = Const
end
orig 0.998054361
orig 1.001007531
orig 0.97477283
orig 0.970671065
orig 0.981895979
orig 0.976570228
orig 0.999720722
orig 0.979027543
orig 1.003703838
orig 0.991378558
cifn 0.975857925
cifn 0.980047733
cifn 0.975872745
cifn 0.990620908
cifn 0.97900539
cifn 1.006296665
cifn 0.980414744
cifn 0.975898369
cifn 0.975216105
cifn 0.97689436
-----------------------------------------------------------
vm1_ensure
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
begin
begin
ensure
end
ensure
end
end
orig 0.72849756
orig 0.724572558
orig 0.723178597
orig 0.722027023
orig 0.719530547
orig 0.72535835
orig 0.722167393
orig 0.721715386
orig 0.735069388
orig 0.724314026
cifn 0.728667085
cifn 0.724486751
cifn 0.72792779
cifn 0.726349584
cifn 0.726714529
cifn 0.726737725
cifn 0.726714718
cifn 0.726916576
cifn 0.728546177
cifn 0.728603884
-----------------------------------------------------------
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
orig 5.72584737
orig 5.843123995
orig 6.337831629
orig 6.092524558
orig 5.910270568
orig 6.135000584
orig 5.926053547
orig 6.34505079
orig 6.082444483
orig 5.818110802
cifn 5.890750751
cifn 5.913074073
cifn 5.738480104
cifn 6.272736827
cifn 5.777641894
cifn 5.886961638
cifn 5.68593019
cifn 5.935663383
cifn 5.644493328
cifn 5.633786338
-----------------------------------------------------------
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
orig 11.70821347
orig 11.374924477
orig 11.494227983
orig 11.463825923
orig 11.392126892
orig 11.765242356
orig 11.410201234
orig 11.390138015
orig 11.350709028
orig 11.57336049
cifn 11.623880814
cifn 11.52377388
cifn 11.493784663
cifn 11.728058482
cifn 11.480934687
cifn 11.417635542
cifn 11.747695072
cifn 11.79163686
cifn 11.441326094
cifn 11.72045281
-----------------------------------------------------------
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
orig 14.636037388
orig 14.563226545
orig 14.300466096
orig 14.377991737
orig 14.313045542
orig 14.698981547
orig 14.628539886
orig 14.281485647
orig 14.657360539
orig 14.313827501
cifn 14.589788685
cifn 14.568694738
cifn 14.608626503
cifn 14.559889444
cifn 14.776238357
cifn 14.562664137
cifn 14.651566572
cifn 14.80534279
cifn 14.583948354
cifn 14.543953145
-----------------------------------------------------------
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
orig 12.94498338
orig 12.978071128
orig 13.33650086
orig 12.972298401
orig 13.532818428
orig 12.95809795
orig 12.913621897
orig 12.876484703
orig 13.012277713
orig 12.998762755
cifn 13.024002433
cifn 12.981391657
cifn 13.055011383
cifn 13.09118026
cifn 12.982924256
cifn 13.058851868
cifn 13.131867149
cifn 13.030389551
cifn 13.427963456
cifn 12.996833771
-----------------------------------------------------------
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
orig 12.109805643
orig 12.445608129
orig 12.225309918
orig 12.315418889
orig 12.162430692
orig 12.222594939
orig 12.201347983
orig 12.223052433
orig 12.1894106
orig 12.128818202
cifn 12.276035912
cifn 12.432983633
cifn 12.271093082
cifn 12.331483044
cifn 12.284553668
cifn 12.256735753
cifn 12.351672312
cifn 12.656904004
cifn 12.524985274
cifn 12.34616724
-----------------------------------------------------------
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
orig 1.413420999
orig 1.397008139
orig 1.424290633
orig 1.406680788
orig 1.419011056
orig 1.338735552
orig 1.403593554
orig 1.424347846
orig 1.405493815
orig 1.392621049
cifn 1.4254258
cifn 1.412521376
cifn 1.418921132
cifn 1.42280268
cifn 1.419879461
cifn 1.418645159
cifn 1.41766208
cifn 1.409899263
cifn 1.46231162
cifn 1.437294352
-----------------------------------------------------------
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
orig 1.373346865
orig 1.392458543
orig 1.371776542
orig 1.462490352
orig 1.366534808
orig 1.374202532
orig 1.420873748
orig 1.474962604
orig 1.390629204
orig 1.393038394
cifn 1.409575713
cifn 1.387175784
cifn 1.579822869
cifn 1.389368269
cifn 1.597334025
cifn 1.388703853
cifn 1.395129925
cifn 1.40050255
cifn 1.59851745
cifn 1.563088419
-----------------------------------------------------------
vm1_ivar
@a = 1
i = 0
while i<30_000_000 # while loop 1
i += 1
j = @a
k = @a
end
orig 1.038170238
orig 1.048873834
orig 1.068459213
orig 1.185032388
orig 1.368334103
orig 1.056111988
orig 1.3754681
orig 1.069903643
orig 1.049317586
orig 1.039877554
cifn 1.214156166
cifn 1.047026677
cifn 1.067565991
cifn 1.04409186
cifn 1.040945278
cifn 1.065755669
cifn 1.361395537
cifn 1.366137011
cifn 1.068527575
cifn 1.106679283
-----------------------------------------------------------
vm1_ivar_set
i = 0
while i<30_000_000 # while loop 1
i += 1
@a = 1
@b = 2
end
orig 1.220756526
orig 1.670117864
orig 1.208740929
orig 1.769581827
orig 1.47378198
orig 1.606856926
orig 1.308339822
orig 1.297540391
orig 1.60653431
orig 1.609697775
cifn 1.226708907
cifn 1.252984766
cifn 1.319685312
cifn 1.330816276
cifn 1.21353386
cifn 1.225841981
cifn 1.313899702
cifn 1.206840802
cifn 1.186710655
cifn 1.290269242
-----------------------------------------------------------
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
orig 1.240063038
orig 1.240028281
orig 1.240685368
orig 1.235551533
orig 1.241115178
orig 1.237906077
orig 1.236272466
orig 1.23566997
orig 1.235721495
orig 1.238698747
cifn 1.235353511
cifn 1.371896145
cifn 1.437929761
cifn 1.312175238
cifn 1.237057794
cifn 1.241250784
cifn 1.292627556
cifn 1.237356322
cifn 1.440325354
cifn 1.282132191
-----------------------------------------------------------
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
orig 2.358547779
orig 2.299117501
orig 2.352260134
orig 2.221519695
orig 2.468614184
orig 2.280334227
orig 2.237958904
orig 2.433781184
orig 2.415239592
orig 2.904685342
cifn 2.2913605
cifn 2.280585556
cifn 2.417093369
cifn 2.269348431
cifn 2.376642169
cifn 2.386889017
cifn 2.285164678
cifn 2.382780985
cifn 2.320017889
cifn 2.238723482
-----------------------------------------------------------
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
orig 2.995329882
orig 2.992943471
orig 3.000223943
orig 2.992772803
orig 2.997685128
orig 2.996838142
orig 2.99588916
orig 2.83965384
orig 2.997385342
orig 3.109699437
cifn 2.993077504
cifn 2.993006981
cifn 3.001798224
cifn 2.998486344
cifn 2.99966452
cifn 3.054609855
cifn 2.997517636
cifn 3.070431635
cifn 2.977024296
cifn 3.069402723
-----------------------------------------------------------
vm1_neq
i = 0
obj1 = Object.new
obj2 = Object.new
while i<30_000_000 # while loop 1
i += 1
obj1 != obj2
end
orig 1.283391383
orig 1.326576797
orig 1.311941055
orig 1.334565437
orig 1.344927236
orig 1.335113057
orig 1.313691868
orig 1.299192181
orig 1.299817688
orig 1.324575688
cifn 1.277178117
cifn 1.280382896
cifn 1.292714628
cifn 1.285199679
cifn 1.283428279
cifn 1.292093172
cifn 1.28068276
cifn 1.284028792
cifn 1.285128303
cifn 1.29639068
-----------------------------------------------------------
vm1_not
i = 0
obj = Object.new
while i<30_000_000 # while loop 1
i += 1
!obj
end
orig 0.958996505
orig 0.968734419
orig 0.965842032
orig 0.959698608
orig 0.964147288
orig 0.969919376
orig 0.968048406
orig 0.972936534
orig 0.98857103
orig 0.960016564
cifn 0.974764902
cifn 0.966510523
cifn 0.967736819
cifn 0.978257068
cifn 0.973517114
cifn 1.039108452
cifn 0.984372757
cifn 0.959990958
cifn 0.970236704
cifn 0.934965316
-----------------------------------------------------------
vm1_rescue
i = 0
while i<30_000_000 # while loop 1
i += 1
begin
rescue
end
end
orig 0.797940356
orig 0.796848596
orig 0.803219469
orig 0.813728068
orig 0.801710641
orig 0.802480522
orig 0.802616005
orig 0.812121848
orig 0.800984686
orig 0.798640898
cifn 0.819192402
cifn 0.81145998
cifn 0.81939201
cifn 0.810220392
cifn 0.807473935
cifn 0.809827158
cifn 0.808666559
cifn 0.812859832
cifn 0.80778833
cifn 0.809845797
-----------------------------------------------------------
vm1_simplereturn
def m
return 1
end
i = 0
while i<30_000_000 # while loop 1
i += 1
m
end
orig 1.706759323
orig 1.643406667
orig 1.711371744
orig 1.643380471
orig 1.640399319
orig 1.711490418
orig 1.635066589
orig 1.708078329
orig 1.637630178
orig 1.658870168
cifn 1.719869327
cifn 1.622500147
cifn 1.644865352
cifn 1.644688405
cifn 1.649928081
cifn 1.646205547
cifn 1.646405568
cifn 1.648378449
cifn 1.642580045
cifn 1.725262045
-----------------------------------------------------------
vm1_swap
a = 1
b = 2
i = 0
while i<30_000_000 # while loop 1
i += 1
a, b = b, a
end
orig 0.93820624
orig 0.937338022
orig 0.937917427
orig 0.950522924
orig 0.938685554
orig 0.93811518
orig 0.938278186
orig 0.941205285
orig 0.937662198
orig 0.940009803
cifn 1.248690137
cifn 0.94055781
cifn 0.951457708
cifn 0.952353428
cifn 0.947515543
cifn 1.26773614
cifn 1.130602745
cifn 0.951344827
cifn 0.948630536
cifn 0.941450917
-----------------------------------------------------------
vm1_yield
def m
i = 0
while i<30_000_000 # while loop 1
i += 1
yield
end
end
m{}
orig 1.617675043
orig 2.034916029
orig 1.594198628
orig 1.615641101
orig 1.682274648
orig 1.61193612
orig 1.614693514
orig 1.613976875
orig 1.614131038
orig 1.674726944
cifn 1.612805795
cifn 1.644468373
cifn 1.603992175
cifn 1.600061645
cifn 1.608533151
cifn 1.606711983
cifn 1.600539377
cifn 1.613496954
cifn 1.571258605
cifn 1.611039502
-----------------------------------------------------------
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
orig 1.17622795
orig 1.183207608
orig 1.167585564
orig 1.167648282
orig 1.167790699
orig 1.174891305
orig 1.189730686
orig 1.161711675
orig 1.166664398
orig 1.158053799
cifn 1.151403821
cifn 1.177709199
cifn 1.143590443
cifn 1.153673964
cifn 1.152730055
cifn 1.184432472
cifn 1.142408797
cifn 1.157098908
cifn 1.178626182
cifn 1.149747746
-----------------------------------------------------------
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
orig 12.283735701
orig 12.185390432
orig 12.12820028
orig 12.242474806
orig 12.208470247
orig 12.274860438
orig 12.200584582
orig 12.24721597
orig 12.112404147
orig 12.172785568
cifn 12.20117444
cifn 12.296717872
cifn 11.792668257
cifn 12.240490693
cifn 11.924703961
cifn 12.23651004
cifn 12.321538713
cifn 12.296749142
cifn 12.152140477
cifn 12.154916643
-----------------------------------------------------------
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
orig 7.199906809
orig 7.117576529
orig 7.105061269
orig 7.108233401
orig 7.207131641
orig 7.0388967
orig 7.076489207
orig 7.099188815
orig 7.091046625
orig 7.039018714
cifn 7.303195047
cifn 7.177661308
cifn 7.108483992
cifn 7.033086729
cifn 7.198849033
cifn 7.09346781
cifn 7.069379204
cifn 7.125642912
cifn 7.084493757
cifn 7.218649317
-----------------------------------------------------------
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
orig 0.280066515
orig 0.278842017
orig 0.279411094
orig 0.342812247
orig 0.27778557
orig 0.279919972
orig 0.279208336
orig 0.276808209
orig 0.286046869
orig 0.278910806
cifn 0.279093349
cifn 0.287073679
cifn 0.277323574
cifn 0.281093756
cifn 0.295780924
cifn 0.277167471
cifn 0.277583271
cifn 0.292773118
cifn 0.281265632
cifn 0.281154022
-----------------------------------------------------------
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
orig 3.396151403
orig 3.424222274
orig 3.394373954
orig 3.507545552
orig 3.468348997
orig 3.391729293
orig 3.410629797
orig 3.454466275
orig 3.428972119
orig 3.525310727
cifn 3.441701011
cifn 3.40657549
cifn 3.405821466
cifn 3.561255615
cifn 3.404120471
cifn 3.406824857
cifn 3.416259064
cifn 3.469239766
cifn 3.397213884
cifn 3.433327978
-----------------------------------------------------------
vm2_dstr
i = 0
x = y = 'z'
while i<6_000_000 # benchmark loop 2
i += 1
str = "foo#{x}bar#{y}baz"
end
orig 1.6614467
orig 1.643377299
orig 1.652054767
orig 1.565676217
orig 1.686924567
orig 1.580453421
orig 1.659607553
orig 1.523304282
orig 1.648859759
orig 1.583219349
cifn 1.632468654
cifn 1.616513769
cifn 1.608221691
cifn 1.605785415
cifn 1.596027586
cifn 1.691109322
cifn 1.646156931
cifn 1.522649047
cifn 1.59286324
cifn 1.678956326
-----------------------------------------------------------
vm2_eval
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
eval("1")
end
orig 27.146856875
orig 23.905694802
orig 26.302987641
orig 23.605928316
orig 26.166821419
orig 23.481633193
orig 26.026274817
orig 25.077783467
orig 24.809354791
orig 24.631226929
cifn 24.975417538
cifn 25.920704613
cifn 24.902006727
cifn 25.892962978
cifn 24.384412239
cifn 25.749207182
cifn 24.645596962
cifn 25.626023792
cifn 23.654279439
cifn 26.053333885
-----------------------------------------------------------
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
orig 1.703984276
orig 1.71814744
orig 1.702229231
orig 1.69889023
orig 1.728599733
orig 1.702876673
orig 1.831706697
orig 1.91636165
orig 1.709404726
orig 2.561432061
cifn 1.698389013
cifn 1.71270991
cifn 1.723007097
cifn 1.728188029
cifn 1.712558607
cifn 1.729617944
cifn 1.725431933
cifn 1.730446431
cifn 1.737158539
cifn 1.734000418
-----------------------------------------------------------
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
orig 2.602446486
orig 3.336102745
orig 2.592085868
orig 2.609839748
orig 2.590929509
orig 2.693334352
orig 2.610793243
orig 2.583756161
orig 2.601243347
orig 2.578143069
cifn 3.329826751
cifn 2.719074822
cifn 2.618853728
cifn 2.548043181
cifn 2.732665942
cifn 2.563831382
cifn 2.580593398
cifn 2.587506507
cifn 2.561537695
cifn 2.581596984
-----------------------------------------------------------
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
orig 1.930038718
orig 1.899227327
orig 1.917113682
orig 1.916524256
orig 1.908679454
orig 2.01487982
orig 1.895686656
orig 1.911218269
orig 1.91416253
orig 1.902448756
cifn 1.969592572
cifn 1.917686524
cifn 1.921619314
cifn 1.947598383
cifn 1.933994075
cifn 2.093937017
cifn 1.926466759
cifn 1.952496179
cifn 1.897283497
cifn 1.94625823
-----------------------------------------------------------
vm2_mutex
require 'thread'
m = Mutex.new
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
m.synchronize{}
end
orig 1.122654223
orig 1.056304248
orig 1.009075071
orig 0.993108311
orig 1.012478202
orig 1.00474949
orig 1.010260971
orig 1.024995809
orig 0.990725582
orig 1.011129448
cifn 1.065989252
cifn 1.038516424
cifn 1.060860222
cifn 1.239764182
cifn 1.0636383
cifn 1.042308652
cifn 1.111517762
cifn 1.058134105
cifn 1.080053958
cifn 1.02104154
-----------------------------------------------------------
vm2_newlambda
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
lambda {}
end
orig 1.323306556
orig 1.32674461
orig 1.35491686
orig 1.327146524
orig 1.36144748
orig 1.389054167
orig 1.324630006
orig 1.340534627
orig 1.3287269
orig 1.3379448
cifn 1.323510013
cifn 1.335933041
cifn 1.34376474
cifn 1.341529518
cifn 1.357273865
cifn 1.347644988
cifn 1.339976009
cifn 1.337507996
cifn 1.371093878
cifn 1.329486131
-----------------------------------------------------------
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
orig 2.63978438
orig 2.658916512
orig 2.628569679
orig 2.918559372
orig 2.588561001
orig 2.623917506
orig 2.614052918
orig 2.730133685
orig 2.624564387
orig 2.623282508
cifn 2.882519274
cifn 2.658612203
cifn 2.61407635
cifn 2.609952873
cifn 2.663443147
cifn 2.755326661
cifn 2.609033108
cifn 2.697293132
cifn 2.597547995
cifn 2.67308239
-----------------------------------------------------------
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
orig 0.31144269
orig 0.311090749
orig 0.310843017
orig 0.310966385
orig 0.312015519
orig 0.31179798
orig 0.34169319
orig 0.311398973
orig 0.313331355
orig 0.312016671
cifn 0.356676202
cifn 0.311939587
cifn 0.312193029
cifn 0.362573791
cifn 0.314025017
cifn 0.366489972
cifn 0.311334091
cifn 0.357727266
cifn 0.31160918
cifn 0.311123993
-----------------------------------------------------------
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
orig 0.628775534
orig 0.628723177
orig 0.630960073
orig 0.640211065
orig 0.646027589
orig 0.688051623
orig 0.647633691
orig 0.628338324
orig 0.676992097
orig 0.681468627
cifn 0.751232934
cifn 0.681151066
cifn 0.68243383
cifn 0.667484491
cifn 0.710285683
cifn 0.676341027
cifn 0.686532954
cifn 0.682888247
cifn 0.659583634
cifn 0.754141219
-----------------------------------------------------------
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
orig 8.980192445
orig 8.899934629
orig 9.331170884
orig 9.083374275
orig 9.180796217
orig 8.860362149
orig 9.122834797
orig 9.234246011
orig 9.285154044
orig 8.896452964
cifn 9.416838322
cifn 10.095227214
cifn 10.028782189
cifn 9.824090694
cifn 9.346592016
cifn 10.077895143
cifn 9.858845104
cifn 9.947929552
cifn 11.131611786
cifn 9.83485344
-----------------------------------------------------------
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
orig 12.650109707
orig 12.636057704
orig 12.450097016
orig 12.598633094
orig 12.543850726
orig 12.648680418
orig 12.978201706
orig 12.546718824
orig 12.671692861
orig 12.356378293
cifn 13.244291828
cifn 13.289123263
cifn 13.111925862
cifn 13.155032681
cifn 13.066821163
cifn 12.564150693
cifn 13.007708644
cifn 13.402638534
cifn 13.699924465
cifn 12.909578664
-----------------------------------------------------------
vm2_regexp
i = 0
str = 'xxxhogexxx'
while i<6_000_000 # benchmark loop 2
/hoge/ =~ str
i += 1
end
orig 1.421230358
orig 1.387812247
orig 1.356057536
orig 1.357772723
orig 1.354027721
orig 1.38942436
orig 1.358919258
orig 1.376728795
orig 1.360951503
orig 1.36006298
cifn 1.260208809
cifn 1.268180452
cifn 1.263553303
cifn 1.271457069
cifn 1.285202372
cifn 1.272144199
cifn 1.260915162
cifn 1.268000807
cifn 1.263820816
cifn 1.310802235
-----------------------------------------------------------
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
orig 0.5633799
orig 0.494838014
orig 0.490506476
orig 0.49868272
orig 0.596157195
orig 0.490894229
orig 0.494946538
orig 0.490291081
orig 0.493285559
orig 0.489794436
cifn 0.498075371
cifn 0.500367396
cifn 0.545061994
cifn 0.497924263
cifn 0.52628202
cifn 0.515662732
cifn 0.495813542
cifn 0.503426751
cifn 0.504228916
cifn 0.503514847
-----------------------------------------------------------
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
orig 0.744727491
orig 0.734728161
orig 0.742153334
orig 0.74211579
orig 0.669811346
orig 0.715842367
orig 0.670949763
orig 0.679437578
orig 0.665938102
orig 0.672297059
cifn 0.669606685
cifn 0.663347159
cifn 0.698743211
cifn 0.665164454
cifn 0.674300394
cifn 0.666669888
cifn 0.70684979
cifn 0.685970821
cifn 0.747716931
cifn 0.668160312
-----------------------------------------------------------
vm2_unif1
i = 0
def m a, b
end
while i<6_000_000 # benchmark loop 2
i += 1
m 100, 200
end
orig 0.367813074
orig 0.366442611
orig 0.363153267
orig 0.379753419
orig 0.368565069
orig 0.454495378
orig 0.362588266
orig 0.36404933
orig 0.36534862
orig 0.364283337
cifn 0.364955714
cifn 0.366759531
cifn 0.362030096
cifn 0.364368607
cifn 0.364921339
cifn 0.380575972
cifn 0.397826977
cifn 0.359662844
cifn 0.383308078
cifn 0.362640825
-----------------------------------------------------------
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
orig 0.684544843
orig 0.701685252
orig 0.798535119
orig 0.725279996
orig 0.711275263
orig 0.706686039
orig 0.711988071
orig 0.805672093
orig 0.766578088
orig 0.813869206
cifn 0.729742525
cifn 0.695842627
cifn 0.680115467
cifn 0.716048177
cifn 0.758254657
cifn 0.75625821
cifn 0.682520595
cifn 0.758310501
cifn 0.690181751
cifn 0.705265169
-----------------------------------------------------------
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
orig 0.216576945
orig 0.217195472
orig 0.218281601
orig 0.215856904
orig 0.223340465
orig 0.21902432
orig 0.217598436
orig 0.214613886
orig 0.219149185
orig 0.213395079
cifn 0.213882479
cifn 0.213188206
cifn 0.213046487
cifn 0.216893977
cifn 0.213688304
cifn 0.213857134
cifn 0.213221006
cifn 0.217493246
cifn 0.218066635
cifn 0.21139822
-----------------------------------------------------------
vm3_clearmethodcache
i = 0
while i<200_000
i += 1
Class.new{
def m; end
}
end
orig 0.640692759
orig 0.643216647
orig 0.641375076
orig 0.64488718
orig 0.637620707
orig 0.64096528
orig 0.642021629
orig 0.647662772
orig 0.652586228
orig 0.640909296
cifn 0.65821298
cifn 0.662065296
cifn 0.653371715
cifn 0.661640451
cifn 0.65391165
cifn 0.647566856
cifn 0.664389209
cifn 0.640851265
cifn 0.659528173
cifn 0.649051833
-----------------------------------------------------------
vm3_gc
#! /usr/bin/ruby
5000.times do
100.times do
{"xxxx"=>"yyyy"}
end
GC.start
end
orig 3.127306834
orig 3.145065126
orig 3.125777562
orig 3.127159401
orig 3.137063487
orig 3.132095425
orig 3.147366128
orig 3.168443721
orig 3.145679353
orig 3.132555675
cifn 3.222056763
cifn 3.199348827
cifn 3.203094304
cifn 3.203402164
cifn 3.219165307
cifn 3.14385807
cifn 3.20927739
cifn 3.27354679
cifn 3.237983098
cifn 3.276681695
-----------------------------------------------------------
vm_thread_alive_check1
5_000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}
orig 0.178072114
orig 0.177874575
orig 0.200387716
orig 0.193972408
orig 0.204927297
orig 0.199902113
orig 0.195788136
orig 0.196947094
orig 0.197972361
orig 0.201103806
cifn 0.19743749
cifn 0.198826945
cifn 0.198124039
cifn 0.202611073
cifn 0.203817124
cifn 0.168551684
cifn 0.163934109
cifn 0.1658303
cifn 0.171342323
cifn 0.167368544
-----------------------------------------------------------
vm_thread_close
1000.times { Thread.new { sleep } }
i = 0
while i<100_000 # benchmark loop 3
i += 1
IO.pipe.each(&:close)
end
orig 3.930110869
orig 3.858739646
orig 3.964089857
orig 3.888285202
orig 3.928121268
orig 3.879594207
orig 3.857259529
orig 3.862815834
orig 3.975321165
orig 3.881143491
cifn 3.96867848
cifn 3.93738096
cifn 4.034013636
cifn 3.924219385
cifn 3.931609981
cifn 3.967952412
cifn 3.995319677
cifn 4.053628378
cifn 3.880437303
cifn 3.933546273
-----------------------------------------------------------
vm_thread_create_join
i = 0
while i<100_000 # benchmark loop 3
i += 1
Thread.new{
}.join
end
orig 1.974668456
orig 1.95364574
orig 2.106791582
orig 1.95229539
orig 1.966641327
orig 2.304212013
orig 1.964966211
orig 1.971958531
orig 2.143665361
orig 2.210865116
cifn 1.972785551
cifn 1.973655423
cifn 2.252431445
cifn 2.021603922
cifn 2.138001623
cifn 1.962643981
cifn 1.97273329
cifn 2.176407227
cifn 1.978388364
cifn 1.969571578
-----------------------------------------------------------
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