Instantly share code, notes, and snippets.

Embed
What would you like to do?
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 2.
2017-11-14 16:00:25 +0900
target 0: ruby_2_4 (ruby 2.4.3p202 (2017-11-03 revision 60626) [x86_64-linux]) at "~/ruby/install/ruby_2_4/bin/ruby"
target 1: trunk_oct (ruby 2.5.0dev (2017-09-30 trunk 60079) [x86_64-linux]) at "~/ruby/install/trunk_r60079/bin/ruby"
target 2: trunk (ruby 2.5.0dev (2017-11-14 trunk 60762) [x86_64-linux]) at "~/ruby/install/trunk/bin/ruby"
target 3: modified (ruby 2.5.0dev (2017-11-14 remove_trace 60762) [x86_64-linux]
last_commit=fix trace-on process) at "~/ruby/install/gitruby/bin/ruby"
measure target: real
-----------------------------------------------------------
app_answer
def ack(m, n)
if m == 0 then
n + 1
elsif n == 0 then
ack(m - 1, 1)
else
ack(m - 1, ack(m, n - 1))
end
end
def the_answer_to_life_the_universe_and_everything
(ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i
end
answer = the_answer_to_life_the_universe_and_everything
ruby_2_4 0.04487689025700092
ruby_2_4 0.044887082651257515
ruby_2_4 0.04478233680129051
ruby_2_4 0.044680457562208176
ruby_2_4 0.044472331181168556
trunk_oct 0.05369561351835728
trunk_oct 0.05327794328331947
trunk_oct 0.053324973210692406
trunk_oct 0.0533294128254056
trunk_oct 0.05318734794855118
trunk 0.05527955200523138
trunk 0.05591896828263998
trunk 0.055002798326313496
trunk 0.055259526707232
trunk 0.05526765063405037
modified 0.05576000455766916
modified 0.056411576457321644
modified 0.05564382392913103
modified 0.05569745972752571
modified 0.055554790422320366
-----------------------------------------------------------
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)
# Subsampling
nsubsamples.times do |v|
nsubsamples.times do |u|
cnt = cnt + 1
wf = w.to_f
hf = h.to_f
xf = x.to_f
yf = y.to_f
uf = u.to_f
vf = v.to_f
px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)
eye = Vec.new(px, py, -1.0).vnormalize
ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)
isect = Isect.new
@spheres[0].intersect(ray, isect)
@spheres[1].intersect(ray, isect)
@spheres[2].intersect(ray, isect)
@plane.intersect(ray, isect)
if isect.hit then
col = ambient_occlusion(isect)
rad.x = rad.x + col.x
rad.y = rad.y + col.y
rad.z = rad.z + col.z
end
end
end
r = rad.x / (nsf * nsf)
g = rad.y / (nsf * nsf)
b = rad.z / (nsf * nsf)
printf("%c", clamp(r))
printf("%c", clamp(g))
printf("%c", clamp(b))
end
nil
end
nil
end
end
alias printf_orig printf
def printf *args
end
# File.open("ao.ppm", "w") do |fp|
printf("P6\n")
printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT)
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
# end
undef printf
alias printf printf_orig
ruby_2_4 36.20966003648937
ruby_2_4 36.276483993045986
ruby_2_4 36.06006149761379
ruby_2_4 36.40027827769518
ruby_2_4 36.59175945352763
trunk_oct 43.17953597661108
trunk_oct 39.5161963775754
trunk_oct 40.67096074577421
trunk_oct 38.93619007524103
trunk_oct 38.87406879570335
trunk 38.30207220930606
trunk 38.3029449256137
trunk 39.2404085919261
trunk 39.17272327654064
trunk 38.36024654470384
modified 37.33606534730643
modified 37.78875325806439
modified 37.444791925139725
modified 37.156153441406786
modified 38.43332130461931
-----------------------------------------------------------
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__
<html>
<head> <%= title %> </head>
<body>
<h1> <%= title %> </h1>
<p>
<%= content %>
</p>
</body>
</html>
ruby_2_4 1.0910273203626275
ruby_2_4 1.1160900527611375
ruby_2_4 1.1138797011226416
ruby_2_4 1.1137238182127476
ruby_2_4 1.0859335204586387
trunk_oct 0.8029095465317369
trunk_oct 0.8081927429884672
trunk_oct 0.8069239566102624
trunk_oct 0.8096117489039898
trunk_oct 0.8034359868615866
trunk 0.8403531908988953
trunk 0.8421134259551764
trunk 0.8327486971393228
trunk 0.8372374074533582
trunk 0.8351303180679679
modified 0.8252536691725254
modified 0.831566384062171
modified 0.8288772627711296
modified 0.8264654008671641
modified 0.8336413651704788
-----------------------------------------------------------
app_factorial
def fact(n)
if(n > 1)
n * fact(n-1)
else
1
end
end
100.times {
fact(5000)
}
ruby_2_4 0.603745648637414
ruby_2_4 0.6038031615316868
ruby_2_4 0.6046772794798017
ruby_2_4 0.6043389672413468
ruby_2_4 0.6039576455950737
trunk_oct 0.669595368206501
trunk_oct 0.6659398227930069
trunk_oct 0.6744274199008942
trunk_oct 0.6669504605233669
trunk_oct 0.6685555214062333
trunk 0.6079981550574303
trunk 0.6069057630375028
trunk 0.6096790451556444
trunk 0.6078688716515899
trunk 0.6082294499501586
modified 0.6126801799982786
modified 0.6108460640534759
modified 0.6114145591855049
modified 0.6117470702156425
modified 0.6101243132725358
-----------------------------------------------------------
app_fib
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end
fib(34)
ruby_2_4 0.36114765889942646
ruby_2_4 0.33853843063116074
ruby_2_4 0.3421305660158396
ruby_2_4 0.34071844164282084
ruby_2_4 0.34828669764101505
trunk_oct 0.4085798738524318
trunk_oct 0.38410656433552504
trunk_oct 0.39509366918355227
trunk_oct 0.4005908276885748
trunk_oct 0.38477741554379463
trunk 0.4005790390074253
trunk 0.39988459181040525
trunk 0.4004660816863179
trunk 0.3989400062710047
trunk 0.4002835098654032
modified 0.3631491204723716
modified 0.35965136997401714
modified 0.361650213599205
modified 0.35752243362367153
modified 0.36000645998865366
-----------------------------------------------------------
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
ruby_2_4 36.53207976743579
ruby_2_4 37.89537764713168
ruby_2_4 36.723573193885386
ruby_2_4 38.48227261565626
ruby_2_4 36.90794064849615
trunk_oct 36.873438694514334
trunk_oct 36.245762643404305
trunk_oct 35.49768565688282
trunk_oct 35.30468615423888
trunk_oct 34.43972430471331
trunk 33.43890817370266
trunk 32.89311058353633
trunk 34.13755172677338
trunk 36.41347415372729
trunk 34.11650806944817
modified 33.69486961700022
modified 33.82463005371392
modified 33.184486526064575
modified 32.46442792471498
modified 31.319396573118865
-----------------------------------------------------------
app_mandelbrot
require 'complex'
def mandelbrot? z
i = 0
while i<100
i += 1
z = z * z
return false if z.abs > 2
end
true
end
ary = []
(0..1000).each{|dx|
(0..1000).each{|dy|
x = dx / 50.0
y = dy / 50.0
c = Complex(x, y)
ary << c if mandelbrot?(c)
}
}
ruby_2_4 0.925727934576571
ruby_2_4 0.9439300484955311
ruby_2_4 0.9091543704271317
ruby_2_4 0.9452749313786626
ruby_2_4 0.9127898877486587
trunk_oct 0.9456870397552848
trunk_oct 0.9509583497419953
trunk_oct 0.9463692363351583
trunk_oct 0.9440803667530417
trunk_oct 0.9558739792555571
trunk 0.952283376827836
trunk 0.9713358459994197
trunk 0.9485433483496308
trunk 0.9530115472152829
trunk 0.9520656513050199
modified 0.9396216114982963
modified 0.9364266060292721
modified 0.9358242331072688
modified 0.9580141827464104
modified 0.9555799597874284
-----------------------------------------------------------
app_pentomino
#!/usr/local/bin/ruby
# This program is contributed by Shin Nishiyama
# modified by K.Sasada
NP = 5
ROW = 8 + NP
COL = 8
$p = []
$b = []
$no = 0
def piece(n, a, nb)
nb.each{|x|
a[n] = x
if n == NP-1
$p << [a.sort]
else
nbc=nb.dup
[-ROW, -1, 1, ROW].each{|d|
if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
nbc << x+d
end
}
nbc.delete x
piece(n+1,a[0..n],nbc)
end
}
end
def kikaku(a)
a.collect {|x| x - a[0]}
end
def ud(a)
kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort)
end
def rl(a)
kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort)
end
def xy(a)
kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort)
end
def mkpieces
piece(0,[],[0])
$p.each do |a|
a0 = a[0]
a[1] = ud(a0)
a[2] = rl(a0)
a[3] = ud(rl(a0))
a[4] = xy(a0)
a[5] = ud(xy(a0))
a[6] = rl(xy(a0))
a[7] = ud(rl(xy(a0)))
a.sort!
a.uniq!
end
$p.uniq!.sort! {|x,y| x[0] <=> y[0] }
end
def mkboard
(0...ROW*COL).each{|i|
if i % ROW >= ROW-NP
$b[i] = -2
else
$b[i] = -1
end
$b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2
}
end
def pboard
return # skip print
print "No. #$no\n"
(0...COL).each{|i|
print "|"
(0...ROW-NP).each{|j|
x = $b[i*ROW+j]
if x < 0
print "..|"
else
printf "%2d|",x+1
end
}
print "\n"
}
print "\n"
end
$pnum=[]
def setpiece(a,pos)
if a.length == $p.length then
$no += 1
pboard
return
end
while $b[pos] != -1
pos += 1
end
($pnum - a).each do |i|
$p[i].each do |x|
f = 0
x.each{|s|
if $b[pos+s] != -1
f=1
break
end
}
if f == 0 then
x.each{|s|
$b[pos+s] = i
}
a << i
setpiece(a.dup, pos)
a.pop
x.each{|s|
$b[pos+s] = -1
}
end
end
end
end
mkpieces
mkboard
$p[4] = [$p[4][0]]
$pnum = (0...$p.length).to_a
setpiece([],0)
__END__
# original
NP = 5
ROW = 8 + NP
COL = 8
$p = []
$b = []
$no = 0
def piece(n,a,nb)
for x in nb
a[n] = x
if n == NP-1
$p << [a.sort]
else
nbc=nb.dup
for d in [-ROW, -1, 1, ROW]
if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
nbc << x+d
end
end
nbc.delete x
piece(n+1,a[0..n],nbc)
end
end
end
def kikaku(a)
a.collect {|x| x - a[0]}
end
def ud(a)
kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort)
end
def rl(a)
kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort)
end
def xy(a)
kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort)
end
def mkpieces
piece(0,[],[0])
$p.each do |a|
a0 = a[0]
a[1] = ud(a0)
a[2] = rl(a0)
a[3] = ud(rl(a0))
a[4] = xy(a0)
a[5] = ud(xy(a0))
a[6] = rl(xy(a0))
a[7] = ud(rl(xy(a0)))
a.sort!
a.uniq!
end
$p.uniq!.sort! {|x,y| x[0] <=> y[0] }
end
def mkboard
for i in 0...ROW*COL
if i % ROW >= ROW-NP
$b[i] = -2
else
$b[i] = -1
end
$b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2
end
end
def pboard
print "No. #$no\n"
for i in 0...COL
print "|"
for j in 0...ROW-NP
x = $b[i*ROW+j]
if x < 0
print "..|"
else
printf "%2d|",x+1
end
end
print "\n"
end
print "\n"
end
$pnum=[]
def setpiece(a,pos)
if a.length == $p.length then
$no += 1
pboard
return
end
while $b[pos] != -1
pos += 1
end
($pnum - a).each do |i|
$p[i].each do |x|
f = 0
for s in x do
if $b[pos+s] != -1
f=1
break
end
end
if f == 0 then
for s in x do
$b[pos+s] = i
end
a << i
setpiece(a.dup, pos)
a.pop
for s in x do
$b[pos+s] = -1
end
end
end
end
end
mkpieces
mkboard
$p[4] = [$p[4][0]]
$pnum = (0...$p.length).to_a
setpiece([],0)
ruby_2_4 10.340436936356127
ruby_2_4 10.26072520390153
ruby_2_4 10.40820305235684
ruby_2_4 10.290426510386169
ruby_2_4 10.318881308659911
trunk_oct 10.564207458868623
trunk_oct 10.45787581242621
trunk_oct 10.485318578779697
trunk_oct 10.420554504729807
trunk_oct 10.618309519253671
trunk 10.273468842729926
trunk 10.102290431037545
trunk 10.127600049600005
trunk 10.193915856070817
trunk 10.167326777242124
modified 9.924994584172964
modified 9.929463713429868
modified 9.918480903841555
modified 9.88340763002634
modified 9.879915663972497
-----------------------------------------------------------
app_raise
i = 0
while i<300000
i += 1
begin
raise
rescue
end
end
ruby_2_4 0.17838600184768438
ruby_2_4 0.17501006741076708
ruby_2_4 0.17996628675609827
ruby_2_4 0.18227750342339277
ruby_2_4 0.17908358480781317
trunk_oct 0.1874496778473258
trunk_oct 0.19084734097123146
trunk_oct 0.18677002470940351
trunk_oct 0.18702173512429
trunk_oct 0.1870880899950862
trunk 0.18548655975610018
trunk 0.18686705827713013
trunk 0.18463914841413498
trunk 0.18457612302154303
trunk 0.1846449924632907
modified 0.18765069358050823
modified 0.18769632186740637
modified 0.18800458870828152
modified 0.1883128797635436
modified 0.1892009163275361
-----------------------------------------------------------
app_strconcat
i = 0
while i<2_000_000
"#{1+1} #{1+1} #{1+1}"
i += 1
end
ruby_2_4 0.7654742449522018
ruby_2_4 0.7948119519278407
ruby_2_4 0.7673031808808446
ruby_2_4 0.7640487998723984
ruby_2_4 0.7711082641035318
trunk_oct 0.7626644130796194
trunk_oct 0.7309178821742535
trunk_oct 0.7315988969057798
trunk_oct 0.7351448154076934
trunk_oct 0.7301147468388081
trunk 0.7378271007910371
trunk 0.7387549160048366
trunk 0.7378970254212618
trunk 0.7387903444468975
trunk 0.7387805189937353
modified 0.7293761782348156
modified 0.7338413437828422
modified 0.7358414940536022
modified 0.7298681391403079
modified 0.7283730050548911
-----------------------------------------------------------
app_tak
def tak x, y, z
unless y < x
z
else
tak( tak(x-1, y, z),
tak(y-1, z, x),
tak(z-1, x, y))
end
end
tak(18, 9, 0)
ruby_2_4 0.5038435598835349
ruby_2_4 0.5028090076521039
ruby_2_4 0.5219125980511308
ruby_2_4 0.5068032648414373
ruby_2_4 0.5048781149089336
trunk_oct 0.5110951131209731
trunk_oct 0.5248937616124749
trunk_oct 0.5222185803577304
trunk_oct 0.5302830990403891
trunk_oct 0.5173734966665506
trunk 0.5375435454770923
trunk 0.5497156092897058
trunk 0.5430646222084761
trunk 0.5374544756487012
trunk 0.5364547353237867
modified 0.49949335400015116
modified 0.5008256258442998
modified 0.5009597418829799
modified 0.5101037258282304
modified 0.501644229516387
-----------------------------------------------------------
app_tarai
def tarai( x, y, z )
if x <= y
then y
else tarai(tarai(x-1, y, z),
tarai(y-1, z, x),
tarai(z-1, x, y))
end
end
tarai(12, 6, 0)
ruby_2_4 0.4232830246910453
ruby_2_4 0.4196279076859355
ruby_2_4 0.4227399108931422
ruby_2_4 0.4237120309844613
ruby_2_4 0.42692682426422834
trunk_oct 0.44046545308083296
trunk_oct 0.45594013575464487
trunk_oct 0.4436839232221246
trunk_oct 0.46460551489144564
trunk_oct 0.43735334277153015
trunk 0.46855807211250067
trunk 0.4719211347401142
trunk 0.47725564520806074
trunk 0.47434646636247635
trunk 0.4816421000286937
modified 0.4196786815300584
modified 0.4139177994802594
modified 0.4215358402580023
modified 0.41485053300857544
modified 0.41740911919623613
-----------------------------------------------------------
app_uri
require 'uri'
100_000.times{
uri = URI.parse('http://www.ruby-lang.org')
uri.scheme
uri.host
uri.port
}
ruby_2_4 0.46180492267012596
ruby_2_4 0.4573489334434271
ruby_2_4 0.4546288913115859
ruby_2_4 0.4528842447325587
ruby_2_4 0.4509422993287444
trunk_oct 0.4815033273771405
trunk_oct 0.47097593266516924
trunk_oct 0.4757920615375042
trunk_oct 0.466670636087656
trunk_oct 0.470277750864625
trunk 0.45849289186298847
trunk 0.4616105295717716
trunk 0.45852625742554665
trunk 0.4658892685547471
trunk 0.4568141447380185
modified 0.46998004242777824
modified 0.46345530450344086
modified 0.4554989682510495
modified 0.45493804942816496
modified 0.45752451941370964
-----------------------------------------------------------
array_sample_100k_10
arr = [*0...100000]
10_000.times {arr.sample 10}
ruby_2_4 0.02950125839561224
ruby_2_4 0.0292540080845356
ruby_2_4 0.029195214621722698
ruby_2_4 0.029124343767762184
ruby_2_4 0.029260456562042236
trunk_oct 0.03751176968216896
trunk_oct 0.03737057093530893
trunk_oct 0.03721648082137108
trunk_oct 0.03718503285199404
trunk_oct 0.03719606250524521
trunk 0.03838095162063837
trunk 0.03798821475356817
trunk 0.038725041784346104
trunk 0.03827290236949921
trunk 0.03830507304519415
modified 0.04066624119877815
modified 0.040673685260117054
modified 0.04057355597615242
modified 0.040464249439537525
modified 0.04056987911462784
-----------------------------------------------------------
array_sample_100k_11
arr = [*0...100000]
10_000.times {arr.sample 11}
ruby_2_4 0.6606828169897199
ruby_2_4 0.6488657798618078
ruby_2_4 0.6510301260277629
ruby_2_4 0.6499084252864122
ruby_2_4 0.6423075329512358
trunk_oct 0.041237770579755306
trunk_oct 0.04111320525407791
trunk_oct 0.041138594038784504
trunk_oct 0.041162275709211826
trunk_oct 0.040904912166297436
trunk 0.04134767409414053
trunk 0.04158247448503971
trunk 0.04145221598446369
trunk 0.04133627377450466
trunk 0.04167115967720747
modified 0.043928662315011024
modified 0.04390209075063467
modified 0.04394834581762552
modified 0.04403913952410221
modified 0.043743777088820934
-----------------------------------------------------------
array_sample_100k__100
arr = [*0...100000]
10_000.times {arr.sample 100}
ruby_2_4 0.6623934572562575
ruby_2_4 0.6640799958258867
ruby_2_4 0.6602982878684998
ruby_2_4 0.6600730195641518
ruby_2_4 0.6696218233555555
trunk_oct 0.08090994041413069
trunk_oct 0.08101366087794304
trunk_oct 0.08157859649509192
trunk_oct 0.08113863784819841
trunk_oct 0.08121221698820591
trunk 0.08170587196946144
trunk 0.08162978943437338
trunk 0.0808451259508729
trunk 0.08087221439927816
trunk 0.08096039108932018
modified 0.083500437438488
modified 0.08393660746514797
modified 0.08398211933672428
modified 0.08396678324788809
modified 0.0843675248324871
-----------------------------------------------------------
array_sample_100k__1k
arr = [*0...100000]
10_000.times {arr.sample 1000}
ruby_2_4 0.8079767534509301
ruby_2_4 0.8053814945742488
ruby_2_4 0.8116927854716778
ruby_2_4 0.8043063106015325
ruby_2_4 0.8095842115581036
trunk_oct 0.49835555255413055
trunk_oct 0.5142400227487087
trunk_oct 0.498779209330678
trunk_oct 0.4986087568104267
trunk_oct 0.4983958415687084
trunk 0.49240061920136213
trunk 0.4967837706208229
trunk 0.4985520299524069
trunk 0.49130321107804775
trunk 0.49092247523367405
modified 0.5003009000793099
modified 0.49788558296859264
modified 0.4979515112936497
modified 0.503381634131074
modified 0.49630678445100784
-----------------------------------------------------------
array_sample_100k__6k
arr = [*0...100000]
10_000.times {arr.sample 6000}
ruby_2_4 1.5716388328000903
ruby_2_4 1.5782960345968604
ruby_2_4 1.578008184209466
ruby_2_4 1.5681307911872864
ruby_2_4 1.5721359457820654
trunk_oct 1.5956734726205468
trunk_oct 1.5903776213526726
trunk_oct 1.5994160855188966
trunk_oct 1.5982768889516592
trunk_oct 1.6031629657372832
trunk 1.5789744956418872
trunk 1.5713908076286316
trunk 1.5625593094155192
trunk 1.5745469778776169
trunk 1.5728356903418899
modified 1.5852369805797935
modified 1.575236569158733
modified 1.577095023356378
modified 1.5689958641305566
modified 1.5718932738527656
-----------------------------------------------------------
array_sample_100k___10k
arr = [*0...100000]
10_000.times {arr.sample 10_000}
ruby_2_4 2.205017488449812
ruby_2_4 2.171666132286191
ruby_2_4 2.1659449748694897
ruby_2_4 2.165872278623283
ruby_2_4 2.1669661132618785
trunk_oct 2.204504747875035
trunk_oct 2.194258383475244
trunk_oct 2.1962699303403497
trunk_oct 2.195070507004857
trunk_oct 2.249415007419884
trunk 2.1587591804564
trunk 2.1593775739893317
trunk 2.160155759193003
trunk 2.1610017055645585
trunk 2.15755879227072
modified 2.1717774234712124
modified 2.3299802094697952
modified 2.163971151225269
modified 2.158941427245736
modified 2.1660576751455665
-----------------------------------------------------------
array_sample_100k___50k
arr = [*0...100000]
10_000.times {arr.sample 50_000}
ruby_2_4 7.809174820780754
ruby_2_4 7.806549916043878
ruby_2_4 7.715758080594242
ruby_2_4 7.755669089965522
ruby_2_4 7.783610421232879
trunk_oct 7.958461046218872
trunk_oct 7.94976463355124
trunk_oct 7.8647908344864845
trunk_oct 7.912963852286339
trunk_oct 7.913691173307598
trunk 7.787658085115254
trunk 7.74038855265826
trunk 7.752917944453657
trunk 7.768044015392661
trunk 7.820888922549784
modified 7.844436853192747
modified 7.786277565173805
modified 7.81502278149128
modified 7.845739766955376
modified 7.853899677284062
-----------------------------------------------------------
array_shift
require 'benchmark'
Benchmark.bm do |x|
[10_000,1_000_000,100_000_000].each do |n|
ary = Array.new(n,0)
GC.start
x.report("#{n}:shift"){ ary.shift }
(0..4).each do |i|
ary = Array.new(n,0)
GC.start
x.report("#{n}:shift(#{i})"){ ary.shift(i) }
end
end
end
ruby_2_4 3.5863759266212583
ruby_2_4 3.6033725421875715
ruby_2_4 3.594981645233929
ruby_2_4 3.617394160479307
ruby_2_4 3.602064718492329
trunk_oct 3.792987175285816
trunk_oct 3.6687114080414176
trunk_oct 3.6558352252468467
trunk_oct 3.6526988577097654
trunk_oct 3.6570083051919937
trunk 1.961324568837881
trunk 1.9620508551597595
trunk 1.9623122792690992
trunk 1.960218240506947
trunk 2.0169059075415134
modified 1.9611085494980216
modified 1.9610675629228354
modified 1.9606889793649316
modified 1.9566379748284817
modified 1.9610895654186606
-----------------------------------------------------------
array_small_and
MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
(MIN_SIZE..MAX_SIZE).map do |size2|
[Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
end
end
ITERATIONS.times do
ARRAYS.each do |group|
group.each do |arr1, arr2|
arr1 & arr2
end
end
end
ruby_2_4 0.04314385913312435
ruby_2_4 0.042992763221263885
ruby_2_4 0.04247965291142464
ruby_2_4 0.04251945484429598
ruby_2_4 0.04269628319889307
trunk_oct 0.04317949339747429
trunk_oct 0.04326737951487303
trunk_oct 0.043151671066880226
trunk_oct 0.04343361593782902
trunk_oct 0.04334050323814154
trunk 0.04446489177644253
trunk 0.04405117221176624
trunk 0.044496748596429825
trunk 0.0441123666241765
trunk 0.04398850444704294
modified 0.04639121983200312
modified 0.04621213115751743
modified 0.04610369727015495
modified 0.046426533721387386
modified 0.046094074845314026
-----------------------------------------------------------
array_small_diff
MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
(MIN_SIZE..MAX_SIZE).map do |size2|
[Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
end
end
ITERATIONS.times do
ARRAYS.each do |group|
group.each do |arr1, arr2|
arr1 - arr2
end
end
end
ruby_2_4 0.04579384531825781
ruby_2_4 0.04583666939288378
ruby_2_4 0.04647925868630409
ruby_2_4 0.04598063975572586
ruby_2_4 0.045941867865622044
trunk_oct 0.04417698085308075
trunk_oct 0.04424693714827299
trunk_oct 0.044360662810504436
trunk_oct 0.04433419741690159
trunk_oct 0.044364359229803085
trunk 0.04526221193373203
trunk 0.04504249710589647
trunk 0.0447850376367569
trunk 0.04534667916595936
trunk 0.04528128355741501
modified 0.04730869736522436
modified 0.0474362438544631
modified 0.04752052389085293
modified 0.04742819629609585
modified 0.047524972818791866
-----------------------------------------------------------
array_small_or
MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
(MIN_SIZE..MAX_SIZE).map do |size2|
[Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
end
end
ITERATIONS.times do
ARRAYS.each do |group|
group.each do |arr1, arr2|
arr1 | arr2
end
end
end
ruby_2_4 0.04941077437251806
ruby_2_4 0.0490758428350091
ruby_2_4 0.0483282245695591
ruby_2_4 0.048524326644837856
ruby_2_4 0.04835126083344221
trunk_oct 0.05159367062151432
trunk_oct 0.050720677711069584
trunk_oct 0.050714993849396706
trunk_oct 0.050847786478698254
trunk_oct 0.05077840015292168
trunk 0.052041953429579735
trunk 0.052027663215994835
trunk 0.05208864528685808
trunk 0.05207608733326197
trunk 0.05212043598294258
modified 0.054272521287202835
modified 0.054302056320011616
modified 0.05433242954313755
modified 0.05439317785203457
modified 0.05421718955039978
-----------------------------------------------------------
array_sort_block
ary = Array.new(1000) { rand(1000) }
10000.times { ary.sort { |a, b| a <=> b } }
ruby_2_4 4.990935520268977
ruby_2_4 5.008760734461248
ruby_2_4 5.002211184240878
ruby_2_4 5.031768757849932
ruby_2_4 5.010361919179559
trunk_oct 4.620776174589992
trunk_oct 4.6228157775476575
trunk_oct 4.628693396225572
trunk_oct 4.634254821576178
trunk_oct 4.6398517601192
trunk 4.6604104693979025
trunk 4.6803290052339435
trunk 4.695919220335782
trunk 4.698329074308276
trunk 4.676961782388389
modified 4.465667547658086
modified 4.4563381634652615
modified 4.457205110229552
modified 4.442073345184326
modified 4.43261747341603
-----------------------------------------------------------
array_sort_float
arr = Array.new(1000) { rand }
10000.times { arr.sort }
ruby_2_4 2.9691732367500663
ruby_2_4 2.9651240250095725
ruby_2_4 2.9431838244199753
ruby_2_4 2.973076667636633
ruby_2_4 2.967228399589658
trunk_oct 1.5360774910077453
trunk_oct 1.5372640900313854
trunk_oct 1.5914093377068639
trunk_oct 1.530824408866465
trunk_oct 1.540001641958952
trunk 1.6600666958838701
trunk 1.558536239899695
trunk 1.5544176446273923
trunk 1.564120912924409
trunk 1.5635378854349256
modified 1.5336211854591966
modified 1.5208673346787691
modified 1.5700370520353317
modified 1.531577586196363
modified 1.5355555731803179
-----------------------------------------------------------
bighash
h = {}; 5000000.times {|n| h[n] = n }
ruby_2_4 1.1658156188204885
ruby_2_4 1.1619386924430728
ruby_2_4 1.1778438221663237
ruby_2_4 1.177191092632711
ruby_2_4 1.1696994761005044
trunk_oct 1.1916822316125035
trunk_oct 1.1992708332836628
trunk_oct 1.1910538002848625
trunk_oct 1.2156227435916662
trunk_oct 1.1998401647433639
trunk 1.2078109737485647
trunk 1.2166875256225467
trunk 1.2052306067198515
trunk 1.206314828246832
trunk 1.2102624317631125
modified 1.211957766674459
modified 1.2027070298790932
modified 1.2055514501407743
modified 1.2117169462144375
modified 1.2023955518379807
-----------------------------------------------------------
dir_empty_p
require 'tmpdir'
max = 100_000
Dir.mktmpdir('bm_dir_empty_p') do |dir|
max.times { Dir.empty?(dir) }
end
ruby_2_4 0.22107713297009468
ruby_2_4 0.20824912749230862
ruby_2_4 0.21443202625960112
ruby_2_4 0.2158330800011754
ruby_2_4 0.2104991702362895
trunk_oct 0.22432265151292086
trunk_oct 0.2660670196637511
trunk_oct 0.21744792722165585
trunk_oct 0.21820032969117165
trunk_oct 0.21739510353654623
trunk 0.22934256959706545
trunk 0.2406091457232833
trunk 0.22949449252337217
trunk 0.22903573978692293
trunk 0.23602640721946955
modified 0.2354406053200364
modified 0.23155706655234098
modified 0.2339407168328762
modified 0.23286220338195562
modified 0.23001439403742552
-----------------------------------------------------------
erb_render
require 'erb'
data = DATA.read
max = 1_500_000
title = "hello world!"
content = "hello world!\n" * 10
src = "def self.render(title, content); #{ERB.new(data).src}; end"
mod = Module.new
mod.instance_eval(src, "(ERB)")
max.times do
mod.render(title, content)
end
__END__
<html>
<head> <%= title %> </head>
<body>
<h1> <%= title %> </h1>
<p>
<%= content %>
</p>
</body>
</html>
ruby_2_4 2.648871618323028
ruby_2_4 2.601091149263084
ruby_2_4 2.6083217319101095
ruby_2_4 2.6274924371391535
ruby_2_4 2.6040284829214215
trunk_oct 1.0657949335873127
trunk_oct 1.075893527828157
trunk_oct 1.0614414513111115
trunk_oct 1.099606178700924
trunk_oct 1.064248469658196
trunk 1.084544393233955
trunk 1.0845027780160308
trunk 1.0832743281498551
trunk 1.1745046861469746
trunk 1.0948968958109617
modified 1.2614368768408895
modified 1.0565239069983363
modified 1.0615467857569456
modified 1.065241951495409
modified 1.1145551661029458
-----------------------------------------------------------
file_chmod
# chmod file
require 'tempfile'
max = 200_000
tmp = Tempfile.new('chmod')
path = tmp.path
max.times do
File.chmod(0777, path)
end
tmp.close!
ruby_2_4 0.19015854876488447
ruby_2_4 0.19285294879227877
ruby_2_4 0.1905073681846261
ruby_2_4 0.19568252936005592
ruby_2_4 0.19243267178535461
trunk_oct 0.2016332894563675
trunk_oct 0.19890588708221912
trunk_oct 0.20081097353249788
trunk_oct 0.2001079497858882
trunk_oct 0.20737564004957676
trunk 0.22116354294121265
trunk 0.21869436744600534
trunk 0.22755639161914587
trunk 0.21909922547638416
trunk 0.2188980421051383
modified 0.21806801576167345
modified 0.23552309162914753
modified 0.2178712347522378
modified 0.22257215715944767
modified 0.21878324821591377
-----------------------------------------------------------
file_rename
# rename file
require 'tempfile'
max = 100_000
tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ]
a, b = tmp.map { |x| x.path }
max.times do
File.rename(a, b)
File.rename(b, a)
end
tmp.each { |t| t.close! }
ruby_2_4 0.6642924919724464
ruby_2_4 0.6502274638041854
ruby_2_4 0.6562406495213509
ruby_2_4 0.6850288612768054
ruby_2_4 0.6594824707135558
trunk_oct 0.6670955242589116
trunk_oct 0.6725148819386959
trunk_oct 0.664207162335515
trunk_oct 0.6652930174022913
trunk_oct 0.6675800252705812
trunk 0.6808162312954664
trunk 0.68763168156147
trunk 0.6752430256456137
trunk 0.6801165351644158
trunk 0.6752310367301106
modified 0.6756181111559272
modified 0.6772550158202648
modified 0.6776238521561027
modified 0.6753160459920764
modified 0.6779537666589022
-----------------------------------------------------------
hash_aref_dsym
h = {}
syms = ('a'..'z').map { |s| s.to_sym }
syms.each { |s| h[s] = 1 }
200_000.times { syms.each { |s| h[s] } }
ruby_2_4 0.263726475648582
ruby_2_4 0.2761738272383809
ruby_2_4 0.2723959432914853
ruby_2_4 0.26847472228109837
ruby_2_4 0.2680125245824456
trunk_oct 0.2943550646305084
trunk_oct 0.2937017111107707
trunk_oct 0.29192993324249983
trunk_oct 0.2919363062828779
trunk_oct 0.30135550256818533
trunk 0.3101480947807431
trunk 0.314423693343997
trunk 0.31170643866062164
trunk 0.3108241092413664
trunk 0.30914205592125654
modified 0.30534568428993225
modified 0.30895554553717375
modified 0.31122990790754557
modified 0.3072431115433574
modified 0.33601050078868866
-----------------------------------------------------------
hash_aref_dsym_long
# [ruby-core:70129] [Bug #11396]
collection_size = 200000
sample_size = 10000
values = (1..collection_size).to_a.map do |x|
"THIS IS A LONGER STRING THAT IS ALSO UNIQUE #{x}"
end
symbol_hash = {}
values.each do |x|
symbol_hash[x.to_sym] = 1
end
# use the same samples each time to minimize deviations
rng = Random.new(0)
symbol_sample_array = values.sample(sample_size, random: rng).map(&:to_sym)
3000.times do
symbol_sample_array.each { |x| symbol_hash[x] }
end
ruby_2_4 3.175567743368447
ruby_2_4 3.206102818250656
ruby_2_4 3.2415223885327578
ruby_2_4 3.299550731666386
ruby_2_4 3.311943086795509
trunk_oct 3.237652954645455
trunk_oct 3.0586729859933257
trunk_oct 3.3109343741089106
trunk_oct 3.3957728538662195
trunk_oct 3.459920813329518
trunk 3.164889508858323
trunk 3.1942493384703994
trunk 3.189624813385308
trunk 3.1740572210401297
trunk 3.2820500675588846
modified 3.1559967659413815
modified 3.197402344085276
modified 3.2052777437493205
modified 3.282293534837663
modified 3.3287694938480854
-----------------------------------------------------------
hash_aref_fix
h = {}
nums = (1..26).to_a
nums.each { |i| h[i] = i }
200_000.times { nums.each { |s| h[s] } }
ruby_2_4 0.2609948040917516
ruby_2_4 0.2578913839533925
ruby_2_4 0.25224294513463974
ruby_2_4 0.271748811006546
ruby_2_4 0.27248279098421335
trunk_oct 0.29355032555758953
trunk_oct 0.28349983040243387
trunk_oct 0.2936028419062495
trunk_oct 0.3452490037307143
trunk_oct 0.41720787063241005
trunk 0.3100457526743412
trunk 0.2910926891490817
trunk 0.29295599088072777
trunk 0.41942670848220587
trunk 0.2960450313985348
modified 0.2895897263661027
modified 0.27915025781840086
modified 0.2791378078982234
modified 0.2965983608737588
modified 0.28458560444414616
-----------------------------------------------------------
hash_aref_flo
h = {}
strs = [*1..10000].map! {|i| i.fdiv(10)}
strs.each { |s| h[s] = s }
50.times { strs.each { |s| h[s] } }
ruby_2_4 0.0499512767419219
ruby_2_4 0.051750097423791885
ruby_2_4 0.05015122704207897
ruby_2_4 0.04933540336787701
ruby_2_4 0.04952178802341223
trunk_oct 0.05952627211809158
trunk_oct 0.059625888243317604
trunk_oct 0.059829698875546455
trunk_oct 0.060849291272461414
trunk_oct 0.05933453608304262
trunk 0.06063990853726864
trunk 0.060607340186834335
trunk 0.060403233394026756
trunk 0.0609989445656538
trunk 0.06045036483556032
modified 0.062234902754426
modified 0.06396108586341143
modified 0.0621397802606225
modified 0.0630847280845046
modified 0.062187787145376205
-----------------------------------------------------------
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] } }
ruby_2_4 0.3686364060267806
ruby_2_4 0.37831310741603374
ruby_2_4 0.3779862029477954
ruby_2_4 0.3743992382660508
ruby_2_4 0.361598146148026
trunk_oct 0.38061713334172964
trunk_oct 0.3909873841330409
trunk_oct 0.395187652669847
trunk_oct 0.3763585928827524
trunk_oct 0.3905332116410136
trunk 0.39660962857306004
trunk 0.3936945628374815
trunk 0.4377703182399273
trunk 0.40676034800708294
trunk 0.36866373661905527
modified 0.39652410615235567
modified 0.3937609801068902
modified 0.40038585383445024
modified 0.3890699865296483
modified 0.400178880430758
-----------------------------------------------------------
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] } }
ruby_2_4 0.3430917225778103
ruby_2_4 0.32951133884489536
ruby_2_4 0.33487503230571747
ruby_2_4 0.3384719081223011
ruby_2_4 0.33576900139451027
trunk_oct 0.34187883976846933
trunk_oct 0.34241723641753197
trunk_oct 0.34056114312261343
trunk_oct 0.35416494961827993
trunk_oct 0.35687818843871355
trunk 0.3454119525849819
trunk 0.34791990276426077
trunk 0.35336306039243937
trunk 0.35420312639325857
trunk 0.34874989464879036
modified 0.3405866641551256
modified 0.34616814460605383
modified 0.32941246312111616
modified 0.3446532553061843
modified 0.3441737936809659
-----------------------------------------------------------
hash_aref_sym
h = {}
syms = ('a'..'z').to_a
begin
syms = eval("%i[#{syms.join(' ')}]")
rescue SyntaxError # <= 1.9.3
syms.map!(&:to_sym)
end
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
ruby_2_4 0.2723753023892641
ruby_2_4 0.26579560339450836
ruby_2_4 0.2653283290565014
ruby_2_4 0.27019786927849054
ruby_2_4 0.285128521732986
trunk_oct 0.3119408180937171
trunk_oct 0.29992883652448654
trunk_oct 0.29907585494220257
trunk_oct 0.3094273768365383
trunk_oct 0.30554392095655203
trunk 0.3042509751394391
trunk 0.30037481151521206
trunk 0.3012241991236806
trunk 0.29844539798796177
trunk 0.30931904818862677
modified 0.3019282864406705
modified 0.32146325148642063
modified 0.2996023017913103
modified 0.3141472479328513
modified 0.2989084841683507
-----------------------------------------------------------
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?
]
begin
syms = eval("%i[#{syms.join(' ')}]")
rescue SyntaxError # <= 1.9.3
syms.map!(&:to_sym)
end
syms.each { |s| h[s] = s }
200_000.times { syms.each { |s| h[s] } }
ruby_2_4 0.3622218491509557
ruby_2_4 0.4381094928830862
ruby_2_4 0.3674069354310632
ruby_2_4 0.3799957800656557
ruby_2_4 0.3875621594488621
trunk_oct 0.44223527424037457
trunk_oct 0.42702542897313833
trunk_oct 0.4132824158295989
trunk_oct 0.41335222963243723
trunk_oct 0.42288501653820276
trunk 0.4240665137767792
trunk 0.4099509548395872
trunk 0.41233318485319614
trunk 0.4047677731141448
trunk 0.41507475171238184
modified 0.40376974642276764
modified 0.407093895599246
modified 0.40305578522384167
modified 0.42089630104601383
modified 0.4092823453247547
-----------------------------------------------------------
hash_flatten
h = {}
10000.times do |i|
h[i] = nil
end
1000.times do
h.flatten
end
ruby_2_4 0.23931661248207092
ruby_2_4 0.23898044601082802
ruby_2_4 0.2388934502378106
ruby_2_4 0.2389828274026513
ruby_2_4 0.23898828402161598
trunk_oct 0.18286235444247723
trunk_oct 0.18168202694505453
trunk_oct 0.18208450730890036
trunk_oct 0.18146330770105124
trunk_oct 0.18216758500784636
trunk 0.20638114120811224
trunk 0.20617200154811144
trunk 0.20668425224721432
trunk 0.20664830226451159
trunk 0.20640033297240734
modified 0.18963987659662962
modified 0.18995442241430283
modified 0.1893994454294443
modified 0.1897573471069336
modified 0.1897696079686284
-----------------------------------------------------------
hash_ident_flo
h = {}.compare_by_identity
strs = (1..10000).to_a.map!(&:to_f)
strs.each { |s| h[s] = s }
50.times { strs.each { |s| h[s] } }
ruby_2_4 0.04909050464630127
ruby_2_4 0.04922498110681772
ruby_2_4 0.04883077833801508
ruby_2_4 0.0491654546931386
ruby_2_4 0.04862384870648384
trunk_oct 0.05925955902785063
trunk_oct 0.05936989467591047
trunk_oct 0.059128270484507084
trunk_oct 0.05897417291998863
trunk_oct 0.059846263378858566
trunk 0.06017099879682064
trunk 0.0599897475913167
trunk 0.060129120014607906
trunk 0.059829612262547016
trunk 0.059953819029033184
modified 0.06197364069521427
modified 0.06301239226013422
modified 0.06195529829710722
modified 0.06145096942782402
modified 0.06151615083217621
-----------------------------------------------------------
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] } }
ruby_2_4 0.2550027072429657
ruby_2_4 0.25709130242466927
ruby_2_4 0.2795975673943758
ruby_2_4 0.28014630638062954
ruby_2_4 0.2746730362996459
trunk_oct 0.30431725084781647
trunk_oct 0.27907548658549786
trunk_oct 0.3097229143604636
trunk_oct 0.28085173200815916
trunk_oct 0.2814785363152623
trunk 0.30336756259202957
trunk 0.2823643572628498
trunk 0.3062245165929198
trunk 0.3192725069820881
trunk 0.28318785782903433
modified 0.34642425179481506
modified 0.29638210218399763
modified 0.2898220447823405
modified 0.29221873730421066
modified 0.3005418302491307
-----------------------------------------------------------
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] } }
ruby_2_4 0.2589333523064852
ruby_2_4 0.2724173329770565
ruby_2_4 0.2794358851388097
ruby_2_4 0.26604977436363697
ruby_2_4 0.25615649949759245
trunk_oct 0.28422093857079744
trunk_oct 0.29160023387521505
trunk_oct 0.2841336829587817
trunk_oct 0.29316555336117744
trunk_oct 0.29831799305975437
trunk 0.2968236692249775
trunk 0.3070484884083271
trunk 0.29577150382101536
trunk 0.2952602840960026
trunk 0.2905656127259135
modified 0.2833299096673727
modified 0.3000877173617482
modified 0.30436465982347727
modified 0.29478229861706495
modified 0.296668728813529
-----------------------------------------------------------
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] } }
ruby_2_4 0.28064961079508066
ruby_2_4 0.2699139639735222
ruby_2_4 0.2610522909089923
ruby_2_4 0.259786419570446
ruby_2_4 0.2636388372629881
trunk_oct 0.289898619055748
trunk_oct 0.27941754274070263
trunk_oct 0.2989111291244626
trunk_oct 0.30557968094944954
trunk_oct 0.3044827217236161
trunk 0.2841451307758689
trunk 0.29513147193938494
trunk 0.29825274739414454
trunk 0.3008001418784261
trunk 0.29079663939774036
modified 0.2829178422689438
modified 0.2951761847361922
modified 0.29073284193873405
modified 0.2812343193218112
modified 0.2890197755768895
-----------------------------------------------------------
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] } }
ruby_2_4 0.26749170385301113
ruby_2_4 0.25853430200368166
ruby_2_4 0.26072264928370714
ruby_2_4 0.25702809914946556
ruby_2_4 0.27116471622139215
trunk_oct 0.3072659121826291
trunk_oct 0.30654087476432323
trunk_oct 0.3076043529435992
trunk_oct 0.2920140326023102
trunk_oct 0.31216693948954344
trunk 0.30231455527246
trunk 0.3066350994631648
trunk 0.29409283585846424
trunk 0.3120587505400181
trunk 0.30041169468313456
modified 0.2973363669589162
modified 0.3094587540253997
modified 0.3012598352506757
modified 0.3460267363116145
modified 0.2915645893663168
-----------------------------------------------------------
hash_keys
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.keys
end
ruby_2_4 0.09465214144438505
ruby_2_4 0.09494761656969786
ruby_2_4 0.09517013281583786
ruby_2_4 0.09517311304807663
ruby_2_4 0.09566901158541441
trunk_oct 0.10243359114974737
trunk_oct 0.10314598213881254
trunk_oct 0.1023942157626152
trunk_oct 0.10257727932184935
trunk_oct 0.10197165608406067
trunk 0.1065923161804676
trunk 0.1063461247831583
trunk 0.10021214559674263
trunk 0.10675222054123878
trunk 0.1004721550270915
modified 0.10937212035059929
modified 0.10857798904180527
modified 0.10883629694581032
modified 0.10871011950075626
modified 0.10857814364135265
-----------------------------------------------------------
hash_long
k1 = "Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong";
k2 = "Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping";
h = {k1 => 0, k2 => 0};
3000000.times{|i| k = i % 2 ? k2 : k1; h [k] = h[k] + 1}
ruby_2_4 0.6776566496118903
ruby_2_4 0.6738138990476727
ruby_2_4 0.6687519643455744
ruby_2_4 0.6694637639448047
ruby_2_4 0.6692806025967002
trunk_oct 0.576607920229435
trunk_oct 0.583100532181561
trunk_oct 0.5810478115454316
trunk_oct 0.5759585332125425
trunk_oct 0.5758388945832849
trunk 0.5886679319664836
trunk 0.578824719414115
trunk 0.5794282341375947
trunk 0.5891964696347713
trunk 0.5801844587549567
modified 0.5787801658734679
modified 0.5786007614806294
modified 0.5786173976957798
modified 0.5787396812811494
modified 0.5783470449969172
-----------------------------------------------------------
hash_shift
h = {}
10000.times do |i|
h[i] = nil
end
50000.times do
k, v = h.shift
h[k] = v
end
ruby_2_4 0.029302826151251793
ruby_2_4 0.02946515940129757
ruby_2_4 0.02928383182734251
ruby_2_4 0.029138588346540928
ruby_2_4 0.02953410241752863
trunk_oct 0.03826920222491026
trunk_oct 0.038040789775550365
trunk_oct 0.03791420720517635
trunk_oct 0.03813316021114588
trunk_oct 0.03833345044404268
trunk 0.0393370445817709
trunk 0.0394512414932251
trunk 0.03941994905471802
trunk 0.039190332405269146
trunk 0.03947609290480614
modified 0.04173279367387295
modified 0.04142030142247677
modified 0.0414245929569006
modified 0.041482603177428246
modified 0.04123121686279774
-----------------------------------------------------------
hash_shift_u16
h = {}
(16384..65536).each do |i|
h[i] = nil
end
300000.times do
k, v = h.shift
h[k] = v
end
ruby_2_4 0.06899990793317556
ruby_2_4 0.06721921171993017
ruby_2_4 0.0671424102038145
ruby_2_4 0.06842063087970018
ruby_2_4 0.06798364501446486
trunk_oct 0.0758235789835453
trunk_oct 0.07667972147464752
trunk_oct 0.07573583722114563
trunk_oct 0.07633332069963217
trunk_oct 0.0763377146795392
trunk 0.07831694092601538
trunk 0.07861876394599676
trunk 0.07803748268634081
trunk 0.07770607620477676
trunk 0.07872064877301455
modified 0.07910268101841211
modified 0.08106855396181345
modified 0.07938780821859837
modified 0.07960688043385744
modified 0.07941157557070255
-----------------------------------------------------------
hash_shift_u24
h = {}
(0xff4000..0xffffff).each do |i|
h[i] = nil
end
300000.times do
k, v = h.shift
h[k] = v
end
ruby_2_4 0.06821257993578911
ruby_2_4 0.06714130844920874
ruby_2_4 0.06836456805467606
ruby_2_4 0.06916996371001005
ruby_2_4 0.06688732840120792
trunk_oct 0.07595515623688698
trunk_oct 0.07614211458712816
trunk_oct 0.0766504593193531
trunk_oct 0.07583861239254475
trunk_oct 0.07618055399507284
trunk 0.07757530827075243
trunk 0.07761591114103794
trunk 0.07828425709158182
trunk 0.07989687751978636
trunk 0.07830884121358395
modified 0.07936799339950085
modified 0.08005461096763611
modified 0.08000997081398964
modified 0.07990794256329536
modified 0.07945192977786064
-----------------------------------------------------------
hash_shift_u32
h = {}
(0xffff4000..0xffffffff).each do |i|
h[i] = nil
end
300000.times do
k, v = h.shift
h[k] = v
end
ruby_2_4 0.0692470520734787
ruby_2_4 0.06743897125124931
ruby_2_4 0.06738287396728992
ruby_2_4 0.06708309706300497
ruby_2_4 0.06774392630904913
trunk_oct 0.07641611527651548
trunk_oct 0.07598584052175283
trunk_oct 0.07606874126940966
trunk_oct 0.07611617632210255
trunk_oct 0.07661638222634792
trunk 0.0782409030944109
trunk 0.07836768310517073
trunk 0.07830094452947378
trunk 0.07797120045870543
trunk 0.0782504640519619
modified 0.07922205608338118
modified 0.07980144582688808
modified 0.07950060721486807
modified 0.08021101914346218
modified 0.07971761748194695
-----------------------------------------------------------
hash_small2
1000000.times.map{|i| a={}; 2.times{|j| a[j]=j}; a}
ruby_2_4 0.4494409402832389
ruby_2_4 0.4508389215916395
ruby_2_4 0.451890891417861
ruby_2_4 0.45400820206850767
ruby_2_4 0.45705028530210257
trunk_oct 0.4623531950637698
trunk_oct 0.4621663298457861
trunk_oct 0.46354869566857815
trunk_oct 0.46262427791953087
trunk_oct 0.46277075447142124
trunk 0.48058672808110714
trunk 0.47581950295716524
trunk 0.4770717294886708
trunk 0.4768876023590565
trunk 0.47570366598665714
modified 0.4747159481048584
modified 0.47542138025164604
modified 0.48115441482514143
modified 0.47522070351988077
modified 0.47443811874836683
-----------------------------------------------------------
hash_small4
1000000.times.map{|i| a={}; 4.times{|j| a[j]=j}; a}
ruby_2_4 0.5742486761882901
ruby_2_4 0.5974699202924967
ruby_2_4 0.5767933959141374
ruby_2_4 0.5782211907207966
ruby_2_4 0.5712182810530066
trunk_oct 0.5861901910975575
trunk_oct 0.5861655008047819
trunk_oct 0.5861290348693728
trunk_oct 0.6346785500645638
trunk_oct 0.5867755152285099
trunk 0.6085033426061273
trunk 0.6072090184316039
trunk 0.6069953348487616
trunk 0.6076025785878301
trunk 0.6087436396628618
modified 0.6034981710836291
modified 0.604193969629705
modified 0.6024577636271715
modified 0.604750245809555
modified 0.6031058877706528
-----------------------------------------------------------
hash_small8
1000000.times.map{|i| a={}; 8.times{|j| a[j]=j}; a}
ruby_2_4 1.0295241875573993
ruby_2_4 1.1690709693357348
ruby_2_4 1.0750119490548968
ruby_2_4 1.0536391269415617
ruby_2_4 1.0349234230816364
trunk_oct 1.058202332817018
trunk_oct 1.0488654309883714
trunk_oct 1.0568763576447964
trunk_oct 1.0487769413739443
trunk_oct 1.047456793487072
trunk 1.235707575455308
trunk 1.1773730088025331
trunk 1.181349717080593
trunk 1.239696185104549
trunk 1.1787792230024934
modified 1.0944882482290268
modified 1.091933854855597
modified 1.0930390488356352
modified 1.0945343114435673
modified 1.0924241999164224
-----------------------------------------------------------
hash_to_proc
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do |i|
[i].map(&h)
end
ruby_2_4 0.024416503496468067
ruby_2_4 0.024257753044366837
ruby_2_4 0.024156589061021805
ruby_2_4 0.0242291409522295
ruby_2_4 0.024087593890726566
trunk_oct 0.03295538853853941
trunk_oct 0.033053671941161156
trunk_oct 0.03301873616874218
trunk_oct 0.03271505702286959
trunk_oct 0.03284402284771204
trunk 0.033997722901403904
trunk 0.03410301823168993
trunk 0.033932266756892204
trunk 0.03396750520914793
trunk 0.03401686251163483
modified 0.03639744780957699
modified 0.03635264374315739
modified 0.036440882831811905
modified 0.03617205750197172
modified 0.03621793072670698
-----------------------------------------------------------
hash_values
h = {}
10000.times do |i|
h[i] = nil
end
5000.times do
h.values
end
ruby_2_4 0.09482246823608875
ruby_2_4 0.0951392687857151
ruby_2_4 0.09502425231039524
ruby_2_4 0.095138237811625
ruby_2_4 0.09573106747120619
trunk_oct 0.10253547970205545
trunk_oct 0.10209653619676828
trunk_oct 0.10230094008147717
trunk_oct 0.10225026402622461
trunk_oct 0.10090127028524876
trunk 0.1004562433809042
trunk 0.1064581610262394
trunk 0.10636940412223339
trunk 0.10040752310305834
trunk 0.1064596688374877
modified 0.1088621262460947
modified 0.10968368221074343
modified 0.10879790503531694
modified 0.10862477961927652
modified 0.1090538464486599
-----------------------------------------------------------
int_quo
5000000.times { 42.quo(3) }
ruby_2_4 1.7910891138017178
ruby_2_4 1.7285595210269094
ruby_2_4 1.7591103501617908
ruby_2_4 1.7299061687663198
ruby_2_4 1.775772562250495
trunk_oct 0.9134138859808445
trunk_oct 0.9059665594249964
trunk_oct 0.9056594418361783
trunk_oct 0.9054229985922575
trunk_oct 0.928419372998178
trunk 0.9065565336495638
trunk 0.905972296372056
trunk 0.8987451354041696
trunk 0.919618234038353
trunk 0.8996790926903486
modified 0.9016909934580326
modified 0.9023942472413182
modified 0.9089935682713985
modified 0.90226483438164
modified 0.9030623137950897
-----------------------------------------------------------
io_copy_stream_write
# The goal of this is to use a synthetic (non-IO) reader
# to trigger the read/write loop of IO.copy_stream,
# bypassing in-kernel mechanisms like sendfile for zero copy,
# so we wrap the /dev/zero IO object:
class Zero
def initialize
@n = 100000
@in = File.open('/dev/zero', 'rb')
end
def read(len, buf)
return if (@n -= 1) == 0
@in.read(len, buf)
end
end
begin
src = Zero.new
dst = File.open(IO::NULL, 'wb')
n = IO.copy_stream(src, dst)
rescue Errno::ENOENT
# not *nix
end if IO.respond_to?(:copy_stream) && IO.const_defined?(:NULL)
ruby_2_4 0.16210402268916368
ruby_2_4 0.16486232168972492
ruby_2_4 0.16260320134460926
ruby_2_4 0.1673704106360674
ruby_2_4 0.16285186167806387
trunk_oct 0.16517131309956312
trunk_oct 0.16473023127764463
trunk_oct 0.16761245392262936
trunk_oct 0.16392066795378923
trunk_oct 0.1653193812817335
trunk 0.16689542774111032
trunk 0.1713306289166212
trunk 0.16785669792443514
trunk 0.1687092548236251
trunk 0.17021904978901148
modified 0.1704663671553135
modified 0.17199433408677578
modified 0.16818094532936811
modified 0.1791617888957262
modified 0.17123859841376543
-----------------------------------------------------------
io_copy_stream_write_socket
# The goal of this is to use a synthetic (non-IO) reader
# to trigger the read/write loop of IO.copy_stream,
# bypassing in-kernel mechanisms like sendfile for zero copy,
# so we wrap the /dev/zero IO object:
class Zero
def initialize
@n = 100000
@in = File.open('/dev/zero', 'rb')
end
def read(len, buf)
return if (@n -= 1) == 0
@in.read(len, buf)
end
end
begin
require 'socket'
src = Zero.new
rd, wr = UNIXSocket.pair
pid = fork do
wr.close
buf = String.new
while rd.read(16384, buf)
end
end
rd.close
IO.copy_stream(src, wr)
rescue Errno::ENOENT, NotImplementedError, NameError
# not *nix: missing /dev/zero, fork, or UNIXSocket
rescue LoadError # no socket?
ensure
wr.close if wr
Process.waitpid(pid) if pid
end if IO.respond_to?(:copy_stream)
ruby_2_4 0.3203147491440177
ruby_2_4 0.3256166009232402
ruby_2_4 0.31645045056939125
ruby_2_4 0.3181094489991665
ruby_2_4 0.3224779777228832
trunk_oct 0.32048323657363653
trunk_oct 0.333693141117692
trunk_oct 0.32401488348841667
trunk_oct 0.336939106695354
trunk_oct 0.4383966764435172
trunk 0.3204655172303319
trunk 0.3223985591903329
trunk 0.3596854144707322
trunk 0.3231933154165745
trunk 0.32139942422509193
modified 0.3314205938950181
modified 0.33042685873806477
modified 0.32387255039066076
modified 0.32587605249136686
modified 0.33207847736775875
-----------------------------------------------------------
io_file_create
#
# Create files
#
max = 200_000
file = './tmpfile_of_bm_io_file_create'
max.times{
f = open(file, 'w')
f.close#(true)
}
File.unlink(file)
ruby_2_4 0.7999052871018648
ruby_2_4 0.7802762482315302
ruby_2_4 0.7981305615976453
ruby_2_4 0.8176641836762428
ruby_2_4 0.7996335029602051
trunk_oct 0.8188932035118341
trunk_oct 0.8183162622153759
trunk_oct 0.8078320994973183
trunk_oct 0.8258823677897453
trunk_oct 0.8580632116645575
trunk 0.7810021582990885
trunk 0.8000286109745502
trunk 0.8005015533417463
trunk 0.7879576412960887
trunk 0.7909177830442786
modified 0.8119170628488064
modified 0.7866885531693697
modified 0.7928201509639621
modified 0.8005136391147971
modified 0.8375968812033534
-----------------------------------------------------------
io_file_read
#
# Seek and Read file.
#
require 'tempfile'
max = 200_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')
f.write str
max.times{
f.seek 0
f.read
}
ruby_2_4 0.8217237209901214
ruby_2_4 0.8444003714248538
ruby_2_4 0.8303785212337971
ruby_2_4 0.8469831356778741
ruby_2_4 0.8294633002951741
trunk_oct 0.7688569575548172
trunk_oct 0.7721415897831321
trunk_oct 0.8051110897213221
trunk_oct 0.7887211926281452
trunk_oct 0.8064563442021608
trunk 0.7544424263760448
trunk 0.7700773729011416
trunk 0.7584051731973886
trunk 0.7609825311228633
trunk 0.7656487720087171
modified 0.7598473494872451
modified 0.7565656080842018
modified 0.8026420054957271
modified 0.755095761269331
modified 0.7528132116422057
-----------------------------------------------------------
io_file_write
#
# Seek and Write file.
#
require 'tempfile'
max = 200_000
str = "Hello world! " * 1000
f = Tempfile.new('yarv-benchmark')
max.times{
f.seek 0
f.write str
}
ruby_2_4 0.5772966332733631
ruby_2_4 0.5744149908423424
ruby_2_4 0.5781210800632834
ruby_2_4 0.577535237185657
ruby_2_4 0.595387808047235
trunk_oct 0.585019969381392
trunk_oct 0.5834510438144207
trunk_oct 0.5755818607285619
trunk_oct 0.5747231030836701
trunk_oct 0.5832370640709996
trunk 0.5774798141792417
trunk 0.5735156740993261
trunk 0.5775971859693527
trunk 0.5818069921806455
trunk 0.5767041118815541
modified 0.5714107882231474
modified 0.5819572256878018
modified 0.5726626105606556
modified 0.5816189525648952
modified 0.5776834171265364
-----------------------------------------------------------
io_nonblock_noex
nr = 1_000_000
i = 0
msg = '.'
buf = '.'
noex = { exception: false }
begin
r, w = IO.pipe
while i < nr
i += 1
w.write_nonblock(msg, noex)
r.read_nonblock(1, buf, noex)
end
rescue ArgumentError # old Rubies
while i < nr
i += 1
w.write_nonblock(msg)
r.read_nonblock(1, buf)
end
ensure
r.close
w.close
end
ruby_2_4 1.351217346265912
ruby_2_4 1.3710231287404895
ruby_2_4 1.4210442770272493
ruby_2_4 1.339781346730888
ruby_2_4 1.373001316562295
trunk_oct 1.282431822270155
trunk_oct 1.2943201018497348
trunk_oct 1.2761540720239282
trunk_oct 1.2877383586019278
trunk_oct 1.300718992948532
trunk 1.2950346199795604
trunk 1.2903010724112391
trunk 1.3431848688051105
trunk 1.2978426683694124
trunk 1.2955013345927
modified 1.3379434710368514
modified 1.3073850935325027
modified 1.43139236420393
modified 1.3297874238342047
modified 1.3217193624004722
-----------------------------------------------------------
io_nonblock_noex2
nr = 1_000_000
i = 0
msg = '.'
buf = '.'
begin
r, w = IO.pipe
while i < nr
i += 1
w.write_nonblock(msg, exception: false)
r.read_nonblock(1, buf, exception: false)
end
rescue ArgumentError # old Rubies
while i < nr
i += 1
w.write_nonblock(msg)
r.read_nonblock(1, buf)
end
ensure
r.close
w.close
end
ruby_2_4 0.8324068998917937
ruby_2_4 0.8314814483746886
ruby_2_4 0.8269680328667164
ruby_2_4 0.8316371915861964
ruby_2_4 0.8199124159291387
trunk_oct 0.8225545426830649
trunk_oct 0.8366458108648658
trunk_oct 0.8511283118277788
trunk_oct 0.8294539796188474
trunk_oct 0.8529512928798795
trunk 0.8512865994125605
trunk 0.8464699042961001
trunk 0.8392754150554538
trunk 0.8420780496671796
trunk 0.8508471073582768
modified 0.8645479064434767
modified 0.8406872861087322
modified 0.8594023119658232
modified 0.8463565856218338
modified 0.8332216292619705
-----------------------------------------------------------
io_pipe_rw
# Measure uncontended GVL performance via read/write with 1:1 threading
# If we switch to M:N threading, this will benchmark something else...
r, w = IO.pipe
src = '0'.freeze
dst = String.new
i = 0
while i < 1_000_000
i += 1
w.write(src)
r.read(1, dst)
end
w.close
r.close
ruby_2_4 0.7143390085548162
ruby_2_4 0.7022978942841291
ruby_2_4 0.7022813595831394
ruby_2_4 0.7124151447787881
ruby_2_4 0.7000056002289057
trunk_oct 0.7139607220888138
trunk_oct 0.710090241394937
trunk_oct 0.7141006896272302
trunk_oct 0.7125008162111044
trunk_oct 0.7146924622356892
trunk 0.7243178458884358
trunk 0.7200548071414232
trunk 0.7394839841872454
trunk 0.7268596375361085
trunk 0.7209014231339097
modified 0.7262718323618174
modified 0.7193344123661518
modified 0.7222678856924176
modified 0.7509619044139981
modified 0.7261429792270064
-----------------------------------------------------------
io_select
# IO.select performance
w = [ IO.pipe[1] ];
nr = 1000000
nr.times {
IO.select nil, w
}
ruby_2_4 0.9978612475097179
ruby_2_4 0.9951350139454007
ruby_2_4 0.9974106270819902
ruby_2_4 0.9967657895758748
ruby_2_4 1.0035944301635027
trunk_oct 1.0107591282576323
trunk_oct 1.0033363224938512
trunk_oct 1.009982293471694
trunk_oct 1.005640427581966
trunk_oct 1.0018855407834053
trunk 0.9936086991801858
trunk 1.0324719995260239
trunk 1.00522892922163
trunk 1.020094777457416
trunk 0.9990698415786028
modified 1.0174420643597841
modified 1.015567747876048
modified 0.9971954477950931
modified 1.00277444627136
modified 1.026356372050941
-----------------------------------------------------------
io_select2
# IO.select performance. worst case of single fd.
ios = []
nr = 1000000
if defined?(Process::RLIMIT_NOFILE)
max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
else
max = 64
end
puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
((max / 2) - 10).times do
ios.concat IO.pipe
end
last = [ ios[-1] ]
puts "last IO: #{last[0].inspect}"
nr.times do
IO.select nil, last
end
ruby_2_4 1.2514165174216032
ruby_2_4 1.2058365903794765
ruby_2_4 1.2566699665039778
ruby_2_4 1.2180656678974628
ruby_2_4 1.2143642427399755
trunk_oct 1.2226426051929593
trunk_oct 1.2405806230381131
trunk_oct 1.2254924103617668
trunk_oct 1.2207012921571732
trunk_oct 1.2302411468699574
trunk 1.23319860547781
trunk 1.2176413107663393
trunk 1.2214890699833632
trunk 1.242837361060083
trunk 1.2556630987673998
modified 1.2407134361565113
modified 1.223868195898831
modified 1.2421179804950953
modified 1.2392476228997111
modified 1.2411613631993532
-----------------------------------------------------------
io_select3
# IO.select performance. a lot of fd
ios = []
nr = 100
if defined?(Process::RLIMIT_NOFILE)
max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
else
max = 64
end
puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
(max - 10).times do
r, w = IO.pipe
r.close
ios.push w
end
nr.times do
IO.select nil, ios
end
ruby_2_4 0.12176590226590633
ruby_2_4 0.10139702539891005
ruby_2_4 0.1210133982822299
ruby_2_4 0.09872106462717056
ruby_2_4 0.12972754146903753
trunk_oct 0.12838854361325502
trunk_oct 0.12410090956836939
trunk_oct 0.11200020927935839
trunk_oct 0.10974986292421818
trunk_oct 0.11278579756617546
trunk 0.1150733856484294
trunk 0.10835539177060127
trunk 0.1078281830996275
trunk 0.09894286841154099
trunk 0.0969577869400382
modified 0.11497108265757561
modified 0.10831099934875965
modified 0.11509297415614128
modified 0.10960207972675562
modified 0.1161925457417965
-----------------------------------------------------------
loop_for
for i in 1..30_000_000
#
end
ruby_2_4 0.9044722365215421
ruby_2_4 0.8913315301761031
ruby_2_4 0.8917335430160165
ruby_2_4 0.9003735594451427
ruby_2_4 0.891508269123733
trunk_oct 0.9779127929359674
trunk_oct 0.9779272573068738
trunk_oct 0.9824546426534653
trunk_oct 1.226051683537662
trunk_oct 1.049929440021515
trunk 1.0119363153353333
trunk 1.0605404255911708
trunk 1.0116948680952191
trunk 1.0291864844039083
trunk 1.017377712763846
modified 0.9972810121253133
modified 0.9777810694649816
modified 0.9819500455632806
modified 0.9814369948580861
modified 0.9772939933463931
-----------------------------------------------------------
loop_generator
max = 600000
if defined? Fiber
gen = (1..max).each
loop do
gen.next
end
else
require 'generator'
gen = Generator.new((0..max))
while gen.next?
gen.next
end
end
ruby_2_4 0.28958967607468367
ruby_2_4 0.2817333731800318
ruby_2_4 0.30630672723054886
ruby_2_4 0.2807753887027502
ruby_2_4 0.27863746136426926
trunk_oct 0.3039307380095124
trunk_oct 0.3060454139485955
trunk_oct 0.30376856960356236
trunk_oct 0.3065807707607746
trunk_oct 0.30464411806315184
trunk 0.28339630272239447
trunk 0.2835812931880355
trunk 0.28066639322787523
trunk 0.28298798855394125
trunk 0.28092439845204353
modified 0.2857633577659726
modified 0.2886517709121108
modified 0.28970182966440916
modified 0.28230337891727686
modified 0.285346164368093
-----------------------------------------------------------
loop_times
30_000_000.times{|e|}
ruby_2_4 0.800098036415875
ruby_2_4 0.7994052208960056
ruby_2_4 0.81767104472965
ruby_2_4 0.8039096966385841
ruby_2_4 0.9809081982821226
trunk_oct 0.8972129980102181
trunk_oct 0.8951454674825072
trunk_oct 0.895119103603065
trunk_oct 0.8975104046985507
trunk_oct 0.897660561837256
trunk 0.9161784658208489
trunk 0.9009289182722569
trunk 0.9006341714411974
trunk 0.9242716180160642
trunk 0.9066849211230874
modified 0.8799077365547419
modified 0.8780862903222442
modified 0.8784855492413044
modified 0.8822809010744095
modified 0.9416052401065826
-----------------------------------------------------------
loop_whileloop
i = 0
while i<30_000_000 # benchmark loop 1
i += 1
end
ruby_2_4 0.38871809281408787
ruby_2_4 0.38852716889232397
ruby_2_4 0.3900247998535633
ruby_2_4 0.38787161000072956
ruby_2_4 0.4692509137094021
trunk_oct 0.4302550461143255
trunk_oct 0.4261731216683984
trunk_oct 0.4263553023338318
trunk_oct 0.4262999976053834
trunk_oct 0.4261710103601217
trunk 0.44495165906846523
trunk 0.44308482576161623
trunk 0.4439132548868656
trunk 0.5232562273740768
trunk 0.4427309790626168
modified 0.4297006605193019
modified 0.4296526713296771
modified 0.43171786796301603
modified 0.4310999112203717
modified 0.4299190267920494
-----------------------------------------------------------
loop_whileloop2
i = 0
while i< 6_000_000 # benchmark loop 2
i += 1
end
ruby_2_4 0.09508057497441769
ruby_2_4 0.09816205408424139
ruby_2_4 0.09490170422941446
ruby_2_4 0.09514188952744007
ruby_2_4 0.09823123272508383
trunk_oct 0.10931369755417109
trunk_oct 0.10927016381174326
trunk_oct 0.10950556118041277
trunk_oct 0.10906031168997288
trunk_oct 0.10930100549012423
trunk 0.1131787234917283
trunk 0.11350607126951218
trunk 0.11356672924011946
trunk 0.11348916590213776
trunk 0.11342305224388838
modified 0.11254169326275587
modified 0.11256999894976616
modified 0.11183645389974117
modified 0.11254487559199333
modified 0.11250667553395033
-----------------------------------------------------------
marshal_dump_flo
bug10761 = 10000.times.map { |x| x.to_f }
100.times { Marshal.dump(bug10761) }
ruby_2_4 0.2474653758108616
ruby_2_4 0.2463385034352541
ruby_2_4 0.24670730996876955
ruby_2_4 0.2659081034362316
ruby_2_4 0.246890252456069
trunk_oct 0.25504343677312136
trunk_oct 0.25651744566857815
trunk_oct 0.25390689726918936
trunk_oct 0.2542014615610242
trunk_oct 0.25434407591819763
trunk 0.2572882482782006
trunk 0.25845279823988676
trunk 0.2580233821645379
trunk 0.2570078521966934
trunk 0.2581360889598727
modified 0.2605440830811858
modified 0.26057865656912327
modified 0.2618860388174653
modified 0.26100150868296623
modified 0.2605224484577775
-----------------------------------------------------------
marshal_dump_load_geniv
a = ''
a.instance_eval do
@a = :a
@b = :b
@c = :c
end
100000.times do
a = Marshal.load(Marshal.dump(a))
end
#p(a.instance_eval { @a == :a && @b == :b && @c == :c })
ruby_2_4 0.38658848591148853
ruby_2_4 0.38398884423077106
ruby_2_4 0.3930904380977154
ruby_2_4 0.3915357328951359
ruby_2_4 0.3868562411516905
trunk_oct 0.39498877339065075
trunk_oct 0.3954792330041528
trunk_oct 0.3979486972093582
trunk_oct 0.3920952929183841
trunk_oct 0.3908311817795038
trunk 0.3994530038908124
trunk 0.3945854725316167
trunk 0.4059576028957963
trunk 0.3963400172069669
trunk 0.3893438410013914
modified 0.40164520870894194
modified 0.3948695659637451
modified 0.3964743921533227
modified 0.39503393042832613
modified 0.3978611407801509
-----------------------------------------------------------
marshal_dump_load_time
100000.times { Marshal.load(Marshal.dump(Time.now)) }
ruby_2_4 1.1609864998608828
ruby_2_4 1.1564325913786888
ruby_2_4 1.1912339758127928
ruby_2_4 1.166799645870924
ruby_2_4 1.152001416310668
trunk_oct 1.175420201383531
trunk_oct 1.1364163476973772
trunk_oct 1.1284445095807314
trunk_oct 1.162480417639017
trunk_oct 1.1347096469253302
trunk 1.1818950893357396
trunk 1.1549881594255567
trunk 1.2190832709893584
trunk 1.163321797735989
trunk 1.1695076981559396
modified 1.1573536796495318
modified 1.1767047625035048
modified 1.1633068844676018
modified 1.1642479738220572
modified 1.1985326698049903
-----------------------------------------------------------
require
$:.push File.join(File.dirname(__FILE__), "bm_require.data")
1.upto(10000) do |i|
require "c#{i}"
end
$:.pop
ruby_2_4 0.7003255039453506
ruby_2_4 0.6770226173102856
ruby_2_4 0.6845751907676458
ruby_2_4 0.6869270578026772
ruby_2_4 0.6865763831883669
trunk_oct 0.7193482229486108
trunk_oct 0.7275565005838871
trunk_oct 0.7269294839352369
trunk_oct 0.7329859836027026
trunk_oct 0.7227034391835332
trunk 0.7305544791743159
trunk 0.7094148565083742
trunk 0.7062418721616268
trunk 0.7997284382581711
trunk 0.707997677847743
modified 0.7551164655014873
modified 0.7279995884746313
modified 0.7400414794683456
modified 0.7204265147447586
modified 0.7185903489589691
-----------------------------------------------------------
require_thread
$:.push File.join(File.dirname(__FILE__), "bm_require.data")
i=0
t = Thread.new do
while true
i = i+1 # dummy loop
end
end
1.upto(100) do |i|
require "c#{i}"
end
$:.pop
t.kill
ruby_2_4 0.12859986256808043
ruby_2_4 0.1278662383556366
ruby_2_4 17.139101547189057
ruby_2_4 0.12799783889204264
ruby_2_4 14.341372024267912
trunk_oct 0.13724040985107422
trunk_oct 0.13700702134519815
trunk_oct 0.1374838687479496
trunk_oct 0.1369559159502387
trunk_oct 0.236913344822824
trunk 101.16569390054792
trunk 103.43558030668646
trunk 32.263321708887815
trunk 103.76521679852158
trunk 72.00294751580805
modified 62.51455730292946
modified 99.16671017743647
modified 97.66403281129897
modified 82.54443915374577
modified 103.37254293449223
-----------------------------------------------------------
securerandom
require "securerandom"
20_0000.times do
SecureRandom.random_number(100)
end
ruby_2_4 0.1747917402535677
ruby_2_4 0.17374191246926785
ruby_2_4 0.18010317254811525
ruby_2_4 0.17790788505226374
ruby_2_4 0.17303849011659622
trunk_oct 0.22200851701200008
trunk_oct 0.22202838957309723
trunk_oct 0.23062498588114977
trunk_oct 0.22145147435367107
trunk_oct 0.22212802711874247
trunk 0.22578141558915377
trunk 0.22446201462298632
trunk 0.2248234525322914
trunk 0.224688989110291
trunk 0.22262599598616362
modified 0.22193302772939205
modified 0.22469153068959713
modified 0.22500979620963335
modified 0.22283765766769648
modified 0.22584333829581738
-----------------------------------------------------------
so_ackermann
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
def ack(m, n)
if m == 0 then
n + 1
elsif n == 0 then
ack(m - 1, 1)
else
ack(m - 1, ack(m, n - 1))
end
end
NUM = 9
ack(3, NUM)
ruby_2_4 0.394165282137692
ruby_2_4 0.3939297618344426
ruby_2_4 0.39566834177821875
ruby_2_4 0.39374957140535116
ruby_2_4 0.3940361188724637
trunk_oct 0.39930439833551645
trunk_oct 0.39863829407840967
trunk_oct 0.39800180681049824
trunk_oct 0.4183602165430784
trunk_oct 0.40153941605240107
trunk 0.4259690511971712
trunk 0.41846096329391
trunk 0.41895114351063967
trunk 0.4184820372611284
trunk 0.4509238637983799
modified 0.3930969974026084
modified 0.39542569871991873
modified 0.39219037629663944
modified 0.3924806835129857
modified 0.3939360249787569
-----------------------------------------------------------
so_array
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Paul Brannan and Mark Hubbart
n = 9000 # Integer(ARGV.shift || 1)
x = Array.new(n)
y = Array.new(n, 0)
n.times{|bi|
x[bi] = bi + 1
}
(0 .. 999).each do |e|
(n-1).step(0,-1) do |bi|
y[bi] += x.at(bi)
end
end
# puts "#{y.first} #{y.last}"
ruby_2_4 0.8295369409024715
ruby_2_4 0.611743145622313
ruby_2_4 0.6117981057614088
ruby_2_4 0.6140669099986553
ruby_2_4 0.6131450338289142
trunk_oct 0.6552423983812332
trunk_oct 0.6528829522430897
trunk_oct 0.6759208580479026
trunk_oct 0.6562178805470467
trunk_oct 0.6593029722571373
trunk 0.6725892294198275
trunk 0.6728537809103727
trunk 0.6702935108914971
trunk 0.7063782475888729
trunk 0.6745461979880929
modified 0.6619908884167671
modified 0.6562794949859381
modified 0.6586566250771284
modified 0.6556976130232215
modified 0.6578402174636722
-----------------------------------------------------------
so_binary_trees
# The Computer Language Shootout Benchmarks
# http://shootout.alioth.debian.org
#
# contributed by Jesse Millikan
# disable output
alias puts_orig puts
def puts str
# disable puts
end
def item_check(tree)
if tree[0] == nil
tree[1]
else
tree[1] + item_check(tree[0]) - item_check(tree[2])
end
end
def bottom_up_tree(item, depth)
if depth > 0
item_item = 2 * item
depth -= 1
[bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
else
[nil, item, nil]
end
end
max_depth = 16 # ARGV[0].to_i
min_depth = 4
max_depth = min_depth + 2 if min_depth + 2 > max_depth
stretch_depth = max_depth + 1
stretch_tree = bottom_up_tree(0, stretch_depth)
puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
stretch_tree = nil
long_lived_tree = bottom_up_tree(0, max_depth)
min_depth.step(max_depth + 1, 2) do |depth|
iterations = 2**(max_depth - depth + min_depth)
check = 0
for i in 1..iterations
temp_tree = bottom_up_tree(i, depth)
check += item_check(temp_tree)
temp_tree = bottom_up_tree(-i, depth)
check += item_check(temp_tree)
end
puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
end
puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"
undef puts
alias puts puts_orig
ruby_2_4 4.359847350046039
ruby_2_4 4.23919237870723
ruby_2_4 4.257350823841989
ruby_2_4 4.25885096937418
ruby_2_4 4.238811162300408
trunk_oct 4.23889244440943
trunk_oct 4.312817181460559
trunk_oct 4.341334853321314
trunk_oct 4.346625108271837
trunk_oct 4.328528879210353
trunk 4.5401236694306135
trunk 4.593720803968608
trunk 4.559484443627298
trunk 4.56108489818871
trunk 4.6567939799278975
modified 4.43616914562881
modified 4.569371286779642
modified 4.532888426445425
modified 4.684375158511102
modified 4.4301601611077785
-----------------------------------------------------------
so_concatenate
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# based on code from Aristarkh A Zagorodnikov and Dat Nguyen
STUFF = "hello\n"
i = 0
while i<10
i += 1
hello = ''
4_000_000.times do |e|
hello << STUFF
end
end
# puts hello.length
ruby_2_4 2.8542529735714197
ruby_2_4 2.855884239077568
ruby_2_4 2.8499110639095306
ruby_2_4 2.8512823432683945
ruby_2_4 2.8487400403246284
trunk_oct 2.9521667193621397
trunk_oct 2.961184752173722
trunk_oct 2.952890577726066
trunk_oct 2.9514555744826794
trunk_oct 2.9549610558897257
trunk 3.0745205199345946
trunk 3.0743666645139456
trunk 3.0733328694477677
trunk 3.0728870863094926
trunk 3.0723974891006947
modified 2.9682219615206122
modified 3.0021516056731343
modified 2.9623350258916616
modified 2.9560116790235043
modified 3.065779614262283
-----------------------------------------------------------
so_count_words
#!/usr/bin/ruby
# -*- mode: ruby -*-
# $Id: wc-ruby.code,v 1.4 2004/11/13 07:43:32 bfulgham Exp $
# http://www.bagley.org/~doug/shootout/
# with help from Paul Brannan
input = open(File.join(File.dirname($0), 'wc.input'), 'rb')
nl = nw = nc = 0
while true
tmp = input.read(4096) or break
data = tmp << (input.gets || "")
nc += data.length
nl += data.count("\n")
((data.strip! || data).tr!("\n", " ") || data).squeeze!
nw += data.count(" ") + 1
end
# STDERR.puts "#{nl} #{nw} #{nc}"
ruby_2_4 0.13292209431529045
ruby_2_4 0.1329799061641097
ruby_2_4 0.1326249921694398
ruby_2_4 0.13304319884628057
ruby_2_4 0.1329117063432932
trunk_oct 0.1404149578884244
trunk_oct 0.14065165352076292
trunk_oct 0.14067816268652678
trunk_oct 0.14016995206475258
trunk_oct 0.1405358389019966
trunk 0.15460665617138147
trunk 0.1538712540641427
trunk 0.15462887845933437
trunk 0.1546104196459055
trunk 0.15447503607720137
modified 0.1565698916092515
modified 0.1570461504161358
modified 0.15607906877994537
modified 0.15718519035726786
modified 0.15635679382830858
-----------------------------------------------------------
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