2014-09-18 03:57:40 +0000 target 0: orig (ruby 2.2.0dev (2014-09-18 trunk 47622) [x86_64-linux]) at "./b/ruby.orig" target 1: cifn (ruby 2.2.0dev (2014-09-18 trunk 47622) [x86_64-linux]) at "./b/ruby.cifn" ----------------------------------------------------------- app_answer def ack(m, n) if m == 0 then n + 1 elsif n == 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end def the_answer_to_life_the_universe_and_everything (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i end answer = the_answer_to_life_the_universe_and_everything orig 0.05257942993193865 orig 0.052988634910434484 orig 0.052707654889672995 orig 0.05304226092994213 orig 0.05272713862359524 orig 0.052880105562508106 orig 0.05228128796443343 orig 0.052782450802624226 orig 0.0527213211171329 orig 0.05291373608633876 cifn 0.05310806818306446 cifn 0.053376670461148024 cifn 0.05301509704440832 cifn 0.05340977106243372 cifn 0.05324913002550602 cifn 0.05286639789119363 cifn 0.05315868789330125 cifn 0.05296426499262452 cifn 0.05304088396951556 cifn 0.0529875922948122 ----------------------------------------------------------- app_aobench # AO render benchmark # Original program (C) Syoyo Fujita in Javascript (and other languages) # https://code.google.com/p/aobench/ # Ruby(yarv2llvm) version by Hideki Miura # IMAGE_WIDTH = 256 IMAGE_HEIGHT = 256 NSUBSAMPLES = 2 NAO_SAMPLES = 8 class Vec def initialize(x, y, z) @x = x @y = y @z = z end attr_accessor :x, :y, :z def vadd(b) Vec.new(@x + b.x, @y + b.y, @z + b.z) end def vsub(b) Vec.new(@x - b.x, @y - b.y, @z - b.z) end def vcross(b) Vec.new(@y * b.z - @z * b.y, @z * b.x - @x * b.z, @x * b.y - @y * b.x) end def vdot(b) @x * b.x + @y * b.y + @z * b.z end def vlength Math.sqrt(@x * @x + @y * @y + @z * @z) end def vnormalize len = vlength v = Vec.new(@x, @y, @z) if len > 1.0e-17 then v.x = v.x / len v.y = v.y / len v.z = v.z / len end v end end class Sphere def initialize(center, radius) @center = center @radius = radius end attr_reader :center, :radius def intersect(ray, isect) rs = ray.org.vsub(@center) b = rs.vdot(ray.dir) c = rs.vdot(rs) - (@radius * @radius) d = b * b - c if d > 0.0 then t = - b - Math.sqrt(d) if t > 0.0 and t < isect.t then isect.t = t isect.hit = true isect.pl = Vec.new(ray.org.x + ray.dir.x * t, ray.org.y + ray.dir.y * t, ray.org.z + ray.dir.z * t) n = isect.pl.vsub(@center) isect.n = n.vnormalize else 0.0 end end nil end end class Plane def initialize(p, n) @p = p @n = n end def intersect(ray, isect) d = -@p.vdot(@n) v = ray.dir.vdot(@n) v0 = v if v < 0.0 then v0 = -v end if v0 < 1.0e-17 then return end t = -(ray.org.vdot(@n) + d) / v if t > 0.0 and t < isect.t then isect.hit = true isect.t = t isect.n = @n isect.pl = Vec.new(ray.org.x + t * ray.dir.x, ray.org.y + t * ray.dir.y, ray.org.z + t * ray.dir.z) end nil end end class Ray def initialize(org, dir) @org = org @dir = dir end attr_accessor :org, :dir end class Isect def initialize @t = 10000000.0 @hit = false @pl = Vec.new(0.0, 0.0, 0.0) @n = Vec.new(0.0, 0.0, 0.0) end attr_accessor :t, :hit, :pl, :n end def clamp(f) i = f * 255.5 if i > 255.0 then i = 255.0 end if i < 0.0 then i = 0.0 end i.to_i end def otherBasis(basis, n) basis[2] = Vec.new(n.x, n.y, n.z) basis[1] = Vec.new(0.0, 0.0, 0.0) if n.x < 0.6 and n.x > -0.6 then basis[1].x = 1.0 elsif n.y < 0.6 and n.y > -0.6 then basis[1].y = 1.0 elsif n.z < 0.6 and n.z > -0.6 then basis[1].z = 1.0 else basis[1].x = 1.0 end basis[0] = basis[1].vcross(basis[2]) basis[0] = basis[0].vnormalize basis[1] = basis[2].vcross(basis[0]) basis[1] = basis[1].vnormalize end class Scene def initialize @spheres = Array.new @spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5) @spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5) @spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5) @plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0)) end def ambient_occlusion(isect) basis = Array.new otherBasis(basis, isect.n) ntheta = NAO_SAMPLES nphi = NAO_SAMPLES eps = 0.0001 occlusion = 0.0 p0 = Vec.new(isect.pl.x + eps * isect.n.x, isect.pl.y + eps * isect.n.y, isect.pl.z + eps * isect.n.z) nphi.times do |j| ntheta.times do |i| r = rand phi = 2.0 * 3.14159265 * rand x = Math.cos(phi) * Math.sqrt(1.0 - r) y = Math.sin(phi) * Math.sqrt(1.0 - r) z = Math.sqrt(r) rx = x * basis[0].x + y * basis[1].x + z * basis[2].x ry = x * basis[0].y + y * basis[1].y + z * basis[2].y rz = x * basis[0].z + y * basis[1].z + z * basis[2].z raydir = Vec.new(rx, ry, rz) ray = Ray.new(p0, raydir) occisect = Isect.new @spheres[0].intersect(ray, occisect) @spheres[1].intersect(ray, occisect) @spheres[2].intersect(ray, occisect) @plane.intersect(ray, occisect) if occisect.hit then occlusion = occlusion + 1.0 else 0.0 end end end occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f) Vec.new(occlusion, occlusion, occlusion) end def render(w, h, nsubsamples) cnt = 0 nsf = nsubsamples.to_f h.times do |y| w.times do |x| rad = Vec.new(0.0, 0.0, 0.0) # Subsmpling nsubsamples.times do |v| nsubsamples.times do |u| cnt = cnt + 1 wf = w.to_f hf = h.to_f xf = x.to_f yf = y.to_f uf = u.to_f vf = v.to_f px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0) py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0) eye = Vec.new(px, py, -1.0).vnormalize ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye) isect = Isect.new @spheres[0].intersect(ray, isect) @spheres[1].intersect(ray, isect) @spheres[2].intersect(ray, isect) @plane.intersect(ray, isect) if isect.hit then col = ambient_occlusion(isect) rad.x = rad.x + col.x rad.y = rad.y + col.y rad.z = rad.z + col.z end end end r = rad.x / (nsf * nsf) g = rad.y / (nsf * nsf) b = rad.z / (nsf * nsf) printf("%c", clamp(r)) printf("%c", clamp(g)) printf("%c", clamp(b)) end nil end nil end end alias printf_orig printf def printf *args end # File.open("ao.ppm", "w") do |fp| printf("P6\n") printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT) printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT) Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES) # end undef printf alias printf printf_orig orig 42.41246634395793 orig 42.58544506598264 orig 42.09989206911996 orig 43.35295344190672 orig 42.802328668069094 orig 43.65596024598926 orig 42.37428691703826 orig 42.06178659480065 orig 43.90971769671887 orig 42.09763608407229 cifn 41.82318872213364 cifn 44.62380090914667 cifn 44.0087394840084 cifn 42.40663763601333 cifn 42.11306659318507 cifn 41.85538622131571 cifn 42.38862401293591 cifn 42.178813002072275 cifn 42.319158881902695 cifn 42.656558063812554 ----------------------------------------------------------- app_erb # # Create many HTML strings with ERB. # require 'erb' data = DATA.read max = 15_000 title = "hello world!" content = "hello world!\n" * 10 max.times{ ERB.new(data).result(binding) } __END__ <%= title %>

<%= title %>

<%= content %>

orig 0.8637947831302881 orig 0.88153679901734 orig 0.861195673700422 orig 1.0034278249368072 orig 0.8612109730020165 orig 0.8823074433021247 orig 0.8722840729169548 orig 0.860674116294831 orig 0.8551873089745641 orig 0.8569396822713315 cifn 0.8565204818733037 cifn 0.8822052553296089 cifn 0.8688205839134753 cifn 0.8509262199513614 cifn 0.8598275310359895 cifn 0.8923125504516065 cifn 0.85081324307248 cifn 0.8865562309511006 cifn 0.9560771891847253 cifn 0.8470181790180504 ----------------------------------------------------------- app_factorial def fact(n) if(n > 1) n * fact(n-1) else 1 end end 100.times { fact(5000) } orig 0.7513284492306411 orig 0.7114164289087057 orig 0.7204134701751173 orig 0.8440729770809412 orig 0.79326375387609 orig 0.7101208791136742 orig 0.7097399202175438 orig 0.713972067926079 orig 0.7271352079696953 orig 0.7210631789639592 cifn 0.7100625662133098 cifn 0.7123814490623772 cifn 0.7111408626660705 cifn 0.7101548621430993 cifn 0.7113624443300068 cifn 0.7098768670111895 cifn 0.7121061501093209 cifn 0.7130174268968403 cifn 0.7116997423581779 cifn 0.7124134441837668 ----------------------------------------------------------- app_fib def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(34) orig 0.5281550600193441 orig 0.4796713199466467 orig 0.5361128463409841 orig 0.5513782068155706 orig 0.5067117819562554 orig 0.4826864879578352 orig 0.524132848251611 orig 0.5289480052888393 orig 0.48277987679466605 orig 0.5020105820149183 cifn 0.5199759611859918 cifn 0.4993628137744963 cifn 0.4862579829059541 cifn 0.49300128128379583 cifn 0.48723424365743995 cifn 0.6408196659758687 cifn 0.5504600470885634 cifn 0.4847481050528586 cifn 0.4829404279589653 cifn 0.5285266698338091 ----------------------------------------------------------- app_lc_fizzbuzz # # FizzBuzz program using only lambda calculus # # This program is quoted from # "Understanding Computation" by Tom Stuart # http://computationbook.com/ # # You can understand why this program works fine by reading this book. # solution = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] } }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[x]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> n { -> l { -> x { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][l][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][x]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }] } }[-> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> x { f[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { -> n { -> p { -> x { p[n[p][x]] } } }[f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n]][x] }][-> p { -> x { x } }] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][x] }]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]] } }][n]]]] }] FIRST = -> l { LEFT[RIGHT[l]] } IF = -> b { b } LEFT = -> p { p[-> x { -> y { x } } ] } RIGHT = -> p { p[-> x { -> y { y } } ] } IS_EMPTY = LEFT REST = -> l { RIGHT[RIGHT[l]] } def to_integer(proc) proc[-> n { n + 1 }][0] end def to_boolean(proc) IF[proc][true][false] end def to_array(proc) array = [] until to_boolean(IS_EMPTY[proc]) array.push(FIRST[proc]) proc = REST[proc] end array end def to_char(c) '0123456789BFiuz'.slice(to_integer(c)) end def to_string(s) to_array(s).map { |c| to_char(c) }.join end answer = to_array(solution).map do |p| to_string(p) end answer_ary = answer.to_a # puts answer_ary orig 59.519764312077314 orig 59.691475238185376 orig 57.92263191379607 orig 58.35297559900209 orig 56.97886832570657 orig 57.917809234932065 orig 56.91300560720265 orig 56.80392095912248 orig 56.905041325837374 orig 53.64028496388346 cifn 59.46175161795691 cifn 58.14476578775793 cifn 55.84241490019485 cifn 58.10710178082809 cifn 60.02577831922099 cifn 56.75567160034552 cifn 59.03966940008104 cifn 57.11432048911229 cifn 57.41008490510285 cifn 56.2974597257562 ----------------------------------------------------------- app_mandelbrot require 'complex' def mandelbrot? z i = 0 while i<100 i += 1 z = z * z return false if z.abs > 2 end true end ary = [] (0..1000).each{|dx| (0..1000).each{|dy| x = dx / 50.0 y = dy / 50.0 c = Complex(x, y) ary << c if mandelbrot?(c) } } orig 0.9158563730306923 orig 1.422508881893009 orig 1.2910386682488024 orig 0.9078632313758135 orig 1.00333118904382 orig 0.9282781770452857 orig 0.9081584811210632 orig 0.9633489847183228 orig 1.0240757893770933 orig 0.9282754878513515 cifn 1.377823187969625 cifn 1.0356888948008418 cifn 1.016342590097338 cifn 0.9693958261050284 cifn 0.9688935168087482 cifn 0.9451137268915772 cifn 0.9420379446819425 cifn 0.9746982580982149 cifn 0.974052653182298 cifn 0.9865201776847243 ----------------------------------------------------------- app_pentomino #!/usr/local/bin/ruby # This program is contributed by Shin Nishiyama # modified by K.Sasada NP = 5 ROW = 8 + NP COL = 8 $p = [] $b = [] $no = 0 def piece(n, a, nb) nb.each{|x| a[n] = x if n == NP-1 $p << [a.sort] else nbc=nb.dup [-ROW, -1, 1, ROW].each{|d| if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d) nbc << x+d end } nbc.delete x piece(n+1,a[0..n],nbc) end } end def kikaku(a) a.collect {|x| x - a[0]} end def ud(a) kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) end def rl(a) kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) end def xy(a) kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) end def mkpieces piece(0,[],[0]) $p.each do |a| a0 = a[0] a[1] = ud(a0) a[2] = rl(a0) a[3] = ud(rl(a0)) a[4] = xy(a0) a[5] = ud(xy(a0)) a[6] = rl(xy(a0)) a[7] = ud(rl(xy(a0))) a.sort! a.uniq! end $p.uniq!.sort! {|x,y| x[0] <=> y[0] } end def mkboard (0...ROW*COL).each{|i| if i % ROW >= ROW-NP $b[i] = -2 else $b[i] = -1 end $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 } end def pboard return # skip print print "No. #$no\n" (0...COL).each{|i| print "|" (0...ROW-NP).each{|j| x = $b[i*ROW+j] if x < 0 print "..|" else printf "%2d|",x+1 end } print "\n" } print "\n" end $pnum=[] def setpiece(a,pos) if a.length == $p.length then $no += 1 pboard return end while $b[pos] != -1 pos += 1 end ($pnum - a).each do |i| $p[i].each do |x| f = 0 x.each{|s| if $b[pos+s] != -1 f=1 break end } if f == 0 then x.each{|s| $b[pos+s] = i } a << i setpiece(a.dup, pos) a.pop x.each{|s| $b[pos+s] = -1 } end end end end mkpieces mkboard $p[4] = [$p[4][0]] $pnum = (0...$p.length).to_a setpiece([],0) __END__ # original NP = 5 ROW = 8 + NP COL = 8 $p = [] $b = [] $no = 0 def piece(n,a,nb) for x in nb a[n] = x if n == NP-1 $p << [a.sort] else nbc=nb.dup for d in [-ROW, -1, 1, ROW] if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d) nbc << x+d end end nbc.delete x piece(n+1,a[0..n],nbc) end end end def kikaku(a) a.collect {|x| x - a[0]} end def ud(a) kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) end def rl(a) kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) end def xy(a) kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) end def mkpieces piece(0,[],[0]) $p.each do |a| a0 = a[0] a[1] = ud(a0) a[2] = rl(a0) a[3] = ud(rl(a0)) a[4] = xy(a0) a[5] = ud(xy(a0)) a[6] = rl(xy(a0)) a[7] = ud(rl(xy(a0))) a.sort! a.uniq! end $p.uniq!.sort! {|x,y| x[0] <=> y[0] } end def mkboard for i in 0...ROW*COL if i % ROW >= ROW-NP $b[i] = -2 else $b[i] = -1 end $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 end end def pboard print "No. #$no\n" for i in 0...COL print "|" for j in 0...ROW-NP x = $b[i*ROW+j] if x < 0 print "..|" else printf "%2d|",x+1 end end print "\n" end print "\n" end $pnum=[] def setpiece(a,pos) if a.length == $p.length then $no += 1 pboard return end while $b[pos] != -1 pos += 1 end ($pnum - a).each do |i| $p[i].each do |x| f = 0 for s in x do if $b[pos+s] != -1 f=1 break end end if f == 0 then for s in x do $b[pos+s] = i end a << i setpiece(a.dup, pos) a.pop for s in x do $b[pos+s] = -1 end end end end end mkpieces mkboard $p[4] = [$p[4][0]] $pnum = (0...$p.length).to_a setpiece([],0) orig 13.592287241946906 orig 13.537219773046672 orig 13.613378079142421 orig 13.602568802889436 orig 13.615039060357958 orig 14.375361667945981 orig 13.755712745711207 orig 14.203408625908196 orig 13.595322277862579 orig 13.551083656959236 cifn 13.694623158313334 cifn 13.862761250231415 cifn 13.568869498092681 cifn 13.521974727045745 cifn 13.896413899026811 cifn 13.578612913377583 cifn 13.49677571002394 cifn 13.62849277118221 cifn 13.458221517968923 cifn 13.520558033138514 ----------------------------------------------------------- app_raise i = 0 while i<300000 i += 1 begin raise rescue end end orig 0.25056508323177695 orig 0.25650328816846013 orig 0.2488386556506157 orig 0.24997861683368683 orig 0.2507305829785764 orig 0.2808909621089697 orig 0.2527270307764411 orig 0.2506918888539076 orig 0.25104251224547625 orig 0.2596754929982126 cifn 0.25500233797356486 cifn 0.25356292398646474 cifn 0.25498424423858523 cifn 0.25757399713620543 cifn 0.259493590798229 cifn 0.25543013075366616 cifn 0.2589199813082814 cifn 0.2596255801618099 cifn 0.2556665572337806 cifn 0.25503684068098664 ----------------------------------------------------------- app_strconcat i = 0 while i<2_000_000 "#{1+1} #{1+1} #{1+1}" i += 1 end orig 0.9653099561110139 orig 0.9706149473786354 orig 1.0809836010448635 orig 0.9405923648737371 orig 0.9525848398916423 orig 1.078153261449188 orig 0.9793923427350819 orig 0.9485737928189337 orig 0.9481318769976497 orig 0.9427538849413395 cifn 0.9451428181491792 cifn 0.9530939599499106 cifn 1.0177648006938398 cifn 0.9522201791405678 cifn 0.9894512142054737 cifn 0.94447020906955 cifn 0.95221639983356 cifn 0.9474901482462883 cifn 0.9678878053091466 cifn 0.946891131810844 ----------------------------------------------------------- app_tak def tak x, y, z unless y < x z else tak( tak(x-1, y, z), tak(y-1, z, x), tak(z-1, x, y)) end end tak(18, 9, 0) orig 0.8170475792139769 orig 0.7255016439594328 orig 0.7064281622879207 orig 0.7249295762740076 orig 0.7584495786577463 orig 0.773450599052012 orig 0.7377685802057385 orig 0.6736344038508832 orig 0.6939549897797406 orig 0.6621920987963676 cifn 0.7440067790448666 cifn 0.6885389122180641 cifn 0.6728312820196152 cifn 0.6773162297904491 cifn 0.6809741398319602 cifn 0.6707949489355087 cifn 0.6660205279476941 cifn 0.6944706179201603 cifn 0.7128825290128589 cifn 0.6861408608965576 ----------------------------------------------------------- app_tarai def tarai( x, y, z ) if x <= y then y else tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y)) end end tarai(12, 6, 0) orig 0.6790766259655356 orig 0.5508075933903456 orig 0.5897110928781331 orig 0.5472303968854249 orig 0.5463281022384763 orig 0.6285710236988962 orig 0.5683637359179556 orig 0.5561478259041905 orig 0.5616541840136051 orig 0.5916669792495668 cifn 0.5562703860923648 cifn 0.5546185998246074 cifn 0.5526857199147344 cifn 0.5620154198259115 cifn 0.5476050330325961 cifn 0.5473589850589633 cifn 0.5645549460314214 cifn 0.5486984052695334 cifn 0.5605206177569926 cifn 0.6269607078284025 ----------------------------------------------------------- app_uri require 'uri' 100_000.times{ uri = URI.parse('http://www.ruby-lang.org') uri.scheme uri.host uri.port } orig 0.6903444430790842 orig 0.6803427003324032 orig 0.6758159631863236 orig 0.6803599572740495 orig 0.6797265033237636 orig 0.6740725440904498 orig 0.6792063834145665 orig 0.6808212050236762 orig 0.6981387361884117 orig 0.68725690478459 cifn 0.6717491871677339 cifn 0.6742440438829362 cifn 0.7072438290342689 cifn 0.6887068320065737 cifn 0.6684849867597222 cifn 0.7017630911432207 cifn 0.6622142801061273 cifn 0.6640025698579848 cifn 0.6647127801552415 cifn 0.6726493327878416 ----------------------------------------------------------- hash_aref_miss h = {} strs = ('a'..'z').to_a.map!(&:freeze) strs.each { |s| h[s] = s } strs = ('A'..'Z').to_a 200_000.times { strs.each { |s| h[s] } } orig 0.44158908212557435 orig 0.4558134349063039 orig 0.4386075180955231 orig 0.43696421664208174 orig 0.4407332530245185 orig 0.4403720120899379 orig 0.4444943079724908 orig 0.48453993117436767 orig 0.46607058588415384 orig 0.54422761593014 cifn 0.4462700020521879 cifn 0.47179862996563315 cifn 0.45131466165184975 cifn 0.532092266716063 cifn 0.476550224237144 cifn 0.4338651108555496 cifn 0.5667132623493671 cifn 0.4566287621855736 cifn 0.4382036100141704 cifn 0.454946412704885 ----------------------------------------------------------- hash_aref_str h = {} strs = ('a'..'z').to_a.map!(&:freeze) strs.each { |s| h[s] = s } 200_000.times { strs.each { |s| h[s] } } orig 0.42500214325264096 orig 0.4189063608646393 orig 0.47711557196453214 orig 0.42828807095065713 orig 0.5338445049710572 orig 0.42319220723584294 orig 0.45623069582507014 orig 0.49119642609730363 orig 0.429848600178957 orig 0.46245275903493166 cifn 0.6701159910298884 cifn 0.4089686181396246 cifn 0.40925030689686537 cifn 0.43381937174126506 cifn 0.40483769215643406 cifn 0.42416392592713237 cifn 0.5084651689976454 cifn 0.4102638210169971 cifn 0.4443835015408695 cifn 0.42905992502346635 ----------------------------------------------------------- hash_aref_sym h = {} syms = ('a'..'z').to_a.map(&:to_sym) syms.each { |s| h[s] = s } 200_000.times { syms.each { |s| h[s] } } orig 0.6878579095937312 orig 0.7841586908325553 orig 0.8830215092748404 orig 0.7062671920284629 orig 0.7248424659483135 orig 0.6347958319820464 orig 0.6697554411366582 orig 0.7887663492001593 orig 0.7386320601217449 orig 0.7369499169290066 cifn 0.6488635912537575 cifn 0.6608589021489024 cifn 0.6972434180788696 cifn 0.812805145047605 cifn 0.621483048889786 cifn 0.7946501760743558 cifn 0.6382343797013164 cifn 0.6363490428775549 cifn 0.7399979159235954 cifn 0.6982781239785254 ----------------------------------------------------------- hash_aref_sym_long h = {} syms = %w[puts warn syswrite write stat bacon lettuce tomato some symbols in this array may already be interned others should not be hash browns make good breakfast but not cooked using prime numbers shift for division entries delete_if keys exist? ].map!(&:to_sym) syms.each { |s| h[s] = s } 200_000.times { syms.each { |s| h[s] } } orig 1.4631079589016736 orig 1.4349395809695125 orig 2.1809010789729655 orig 1.398252401035279 orig 1.3926060879603028 orig 1.3946027630008757 orig 1.4013608773238957 orig 1.3932259301654994 orig 1.3888474833220243 orig 1.4009313900023699 cifn 1.3957318547181785 cifn 1.4786355192773044 cifn 2.0141567336395383 cifn 1.4708803240209818 cifn 1.3994645662605762 cifn 1.389890344813466 cifn 1.386424247175455 cifn 1.3954951227642596 cifn 1.396771834231913 cifn 1.409946314059198 ----------------------------------------------------------- hash_flatten h = {} 10000.times do |i| h[i] = nil end 1000.times do h.flatten end orig 0.36006529442965984 orig 0.3610790357924998 orig 0.3679026491008699 orig 0.36649705888703465 orig 0.36147047206759453 orig 0.3843677747063339 orig 0.36351129692047834 orig 0.3654408189468086 orig 0.36174418311566114 orig 0.3694863012060523 cifn 0.38159063505008817 cifn 0.3804808449931443 cifn 0.38350735092535615 cifn 0.3836651942692697 cifn 0.38462613709270954 cifn 0.39261791622266173 cifn 0.385337358340621 cifn 0.3881041742861271 cifn 0.3855453319847584 cifn 0.3841234687715769 ----------------------------------------------------------- hash_ident_num h = {}.compare_by_identity nums = (1..26).to_a nums.each { |n| h[n] = n } 200_000.times { nums.each { |n| h[n] } } orig 0.3484656666405499 orig 0.29223034670576453 orig 0.2930339202284813 orig 0.29324609274044633 orig 0.3207020782865584 orig 0.30349195981398225 orig 0.3305353941395879 orig 0.4165099738165736 orig 0.32508466485887766 orig 0.3786970730870962 cifn 0.2933029271662235 cifn 0.30645654490217566 cifn 0.290601696819067 cifn 0.30587953981012106 cifn 0.3090338069014251 cifn 0.29329209588468075 cifn 0.29809318389743567 cifn 0.29216553596779704 cifn 0.29365096101537347 cifn 0.29288870841264725 ----------------------------------------------------------- hash_ident_obj h = {}.compare_by_identity objs = 26.times.map { Object.new } objs.each { |o| h[o] = o } 200_000.times { objs.each { |o| h[o] } } orig 0.3001482058316469 orig 0.3112319689244032 orig 0.3272800580598414 orig 0.31346349185332656 orig 0.2979101799428463 orig 0.312771484721452 orig 0.406793809030205 orig 0.43052043626084924 orig 0.3108465578407049 orig 0.3287119911983609 cifn 0.38682393496856093 cifn 0.2884493679739535 cifn 0.33827286399900913 cifn 0.30481858691200614 cifn 0.28997564502060413 cifn 0.2888402519747615 cifn 0.35073866602033377 cifn 0.29942387202754617 cifn 0.3233624710701406 cifn 0.3587665040977299 ----------------------------------------------------------- hash_ident_str h = {}.compare_by_identity strs = ('a'..'z').to_a strs.each { |s| h[s] = s } 200_000.times { strs.each { |s| h[s] } } orig 0.3023229627870023 orig 0.296729797963053 orig 0.31062123784795403 orig 0.35379406809806824 orig 0.3140300586819649 orig 0.33284231973811984 orig 0.28803117712959647 orig 0.29350109584629536 orig 0.30630866484716535 orig 0.3112529320642352 cifn 0.3337221792899072 cifn 0.3228278271853924 cifn 0.3224711059592664 cifn 0.3197737648151815 cifn 0.31012806901708245 cifn 0.5303662130609155 cifn 0.2985809468664229 cifn 0.3079190729185939 cifn 0.3683091336861253 cifn 0.3261091662570834 ----------------------------------------------------------- hash_ident_sym h = {}.compare_by_identity syms = ('a'..'z').to_a.map(&:to_sym) syms.each { |s| h[s] = s } 200_000.times { syms.each { |s| h[s] } } orig 0.31256977980956435 orig 0.3461852530017495 orig 0.3096718289889395 orig 0.3406308591365814 orig 0.3110129185952246 orig 0.32413317216560245 orig 0.31943668192252517 orig 0.3387451828457415 orig 0.3178816242143512 orig 0.3384987493045628 cifn 0.31473476672545075 cifn 0.3183167609386146 cifn 0.3245344739407301 cifn 0.30698847910389304 cifn 0.36087121069431305 cifn 0.3339608130045235 cifn 0.3491661259904504 cifn 0.33726900909096 cifn 0.3171933772973716 cifn 0.31732219690456986 ----------------------------------------------------------- hash_keys h = {} 10000.times do |i| h[i] = nil end 5000.times do h.keys end orig 0.23431559605523944 orig 0.23627269407734275 orig 0.23426362499594688 orig 0.2347873467952013 orig 0.23471618397161365 orig 0.23421715293079615 orig 0.251118095126003 orig 0.23429796379059553 orig 0.23627043887972832 orig 0.2354375161230564 cifn 0.23579652095213532 cifn 0.23645014688372612 cifn 0.234529091976583 cifn 0.23533294908702374 cifn 0.23544071288779378 cifn 0.23439919017255306 cifn 0.23677499825134873 cifn 0.2356830332428217 cifn 0.2354436321184039 cifn 0.23596369428560138 ----------------------------------------------------------- hash_shift h = {} 10000.times do |i| h[i] = nil end 50000.times do k, v = h.shift h[k] = v end orig 0.036493922118097544 orig 0.036106600891798735 orig 0.036016397178173065 orig 0.03623969107866287 orig 0.03613102901726961 orig 0.036025168374180794 orig 0.03636204404756427 orig 0.03619714314118028 orig 0.03579147206619382 orig 0.03607522929087281 cifn 0.03605530923232436 cifn 0.03623009193688631 cifn 0.036020254250615835 cifn 0.036439419724047184 cifn 0.03618444502353668 cifn 0.03789317002519965 cifn 0.03616941999644041 cifn 0.036313765682280064 cifn 0.03628682205453515 cifn 0.03638553200289607 ----------------------------------------------------------- hash_values h = {} 10000.times do |i| h[i] = nil end 5000.times do h.values end orig 0.245506945066154 orig 0.24418459367007017 orig 0.24439476989209652 orig 0.25654372898861766 orig 0.24893029499799013 orig 0.24737610202282667 orig 0.24499456910416484 orig 0.24691558815538883 orig 0.24392260005697608 orig 0.24560620309785008 cifn 0.24672274105250835 cifn 0.24470549076795578 cifn 0.2458344530314207 cifn 0.2472829930484295 cifn 0.244971277192235 cifn 0.2454515597783029 cifn 0.24463572492823005 cifn 0.24551572324708104 cifn 0.24466190487146378 cifn 0.24551548063755035 ----------------------------------------------------------- io_file_create # # Create files # max = 200_000 file = './tmpfile_of_bm_io_file_create' max.times{ f = open(file, 'w') f.close#(true) } File.unlink(file) orig 1.1214369083754718 orig 1.155666712205857 orig 1.1856497740373015 orig 1.1228825799189508 orig 1.1982325119897723 orig 1.1567604383453727 orig 1.1211237367242575 orig 1.0906907068565488 orig 1.0947977788746357 orig 1.1132661029696465 cifn 1.1115121180191636 cifn 1.1711709229275584 cifn 1.0973494532518089 cifn 1.211423687171191 cifn 1.113156259059906 cifn 1.1665396047756076 cifn 1.0928349709138274 cifn 1.1067049661651254 cifn 1.1156533597968519 cifn 1.1393212019465864 ----------------------------------------------------------- io_file_read # # Seek and Read file. # require 'tempfile' max = 200_000 str = "Hello world! " * 1000 f = Tempfile.new('yarv-benchmark') f.write str max.times{ f.seek 0 f.read } orig 1.0561706768348813 orig 1.107637147884816 orig 1.076987368054688 orig 1.0592068508267403 orig 1.0535091157071292 orig 1.2511895769275725 orig 1.1182194789871573 orig 1.0715780928730965 orig 1.4516188851557672 orig 1.0778630268760026 cifn 1.05537612689659 cifn 1.0614419858902693 cifn 1.0659242449328303 cifn 1.1053725900128484 cifn 1.0604799170978367 cifn 1.08706742990762 cifn 1.0600585006177425 cifn 1.064851796720177 cifn 1.0500153740867972 cifn 1.0726607777178288 ----------------------------------------------------------- io_file_write # # Seek and Write file. # require 'tempfile' max = 200_000 str = "Hello world! " * 1000 f = Tempfile.new('yarv-benchmark') max.times{ f.seek 0 f.write str } orig 0.8019406469538808 orig 0.7991663636639714 orig 0.7828580499626696 orig 0.7883581700734794 orig 0.7870145300403237 orig 0.8844623868353665 orig 0.9177393647842109 orig 0.8035362539812922 orig 0.8010289669036865 orig 0.8203208819031715 cifn 0.8250290560536087 cifn 0.7975404281169176 cifn 0.8175141122192144 cifn 0.8460244541056454 cifn 0.7947121909819543 cifn 0.7974296011961997 cifn 0.7941793082281947 cifn 0.8255473198369145 cifn 0.7827960336580873 cifn 0.7790052322670817 ----------------------------------------------------------- io_select # IO.select performance w = [ IO.pipe[1] ]; nr = 1000000 nr.times { IO.select nil, w } orig 1.2281148969195783 orig 1.2298627840355039 orig 1.2455583857372403 orig 1.2394705028273165 orig 1.2738241087645292 orig 1.2518473011441529 orig 1.2315575191751122 orig 1.2789336591959 orig 1.2294541499577463 orig 1.2518771989271045 cifn 1.2667648973874748 cifn 1.3601264096796513 cifn 1.2423028191551566 cifn 1.2559375958517194 cifn 1.2794280159287155 cifn 1.3435007869265974 cifn 1.248205161653459 cifn 1.238149299286306 cifn 1.255334650631994 cifn 1.2794003612361848 ----------------------------------------------------------- io_select2 # IO.select performance. worst case of single fd. ios = [] nr = 1000000 if defined?(Process::RLIMIT_NOFILE) max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] else max = 64 end puts "max fd: #{max} (results not apparent with <= 1024 max fd)" ((max / 2) - 10).times do ios.concat IO.pipe end last = [ ios[-1] ] puts "last IO: #{last[0].inspect}" nr.times do IO.select nil, last end orig 1.4112921101041138 orig 1.4331367569975555 orig 1.6750108618289232 orig 1.405153414234519 orig 1.3909132396802306 orig 1.6443312298506498 orig 1.50174216972664 orig 1.4006077591329813 orig 1.4237477402202785 orig 1.3939715400338173 cifn 1.4463662933558226 cifn 1.4330173111520708 cifn 1.4129586503840983 cifn 1.420349556952715 cifn 1.403040274977684 cifn 1.3881271751597524 cifn 1.4126368681900203 cifn 1.4814689131453633 cifn 1.4571766001172364 cifn 1.4684141026809812 ----------------------------------------------------------- io_select3 # IO.select performance. a lot of fd ios = [] nr = 100 if defined?(Process::RLIMIT_NOFILE) max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] else max = 64 end puts "max fd: #{max} (results not apparent with <= 1024 max fd)" (max - 10).times do r, w = IO.pipe r.close ios.push w end nr.times do IO.select nil, ios end orig 0.03408223483711481 orig 0.034550419077277184 orig 0.03393869008868933 orig 0.03419269295409322 orig 0.034429037012159824 orig 0.03418709011748433 orig 0.03394354414194822 orig 0.03416124638170004 orig 0.03394103329628706 orig 0.034437986090779305 cifn 0.034745318815112114 cifn 0.03431164100766182 cifn 0.03446725197136402 cifn 0.03480427572503686 cifn 0.03432486904785037 cifn 0.034654513001441956 cifn 0.03445256222039461 cifn 0.034828975796699524 cifn 0.03455076180398464 cifn 0.034519157372415066 ----------------------------------------------------------- loop_for for i in 1..30_000_000 # end orig 1.1558735449798405 orig 1.1144933891482651 orig 1.1994197219610214 orig 1.1862428826279938 orig 1.1505232430063188 orig 1.2077705464325845 orig 1.1438613669015467 orig 1.1505277208052576 orig 1.393432600889355 orig 1.1613395069725811 cifn 1.1465795231051743 cifn 1.1070879688486457 cifn 1.1839722939766943 cifn 1.1819855817593634 cifn 1.1008467990905046 cifn 1.139702942688018 cifn 1.093521477188915 cifn 1.1431650542654097 cifn 1.184655497316271 cifn 1.1709552248939872 ----------------------------------------------------------- loop_generator max = 600000 if defined? Fiber gen = (1..max).each loop do gen.next end else require 'generator' gen = Generator.new((0..max)) while gen.next? gen.next end end orig 0.7570626530796289 orig 0.6679863012395799 orig 0.674208459444344 orig 0.7055424903519452 orig 0.7101334468461573 orig 0.6784016047604382 orig 0.7320532738231122 orig 0.6803545756265521 orig 0.6689452370628715 orig 0.6867761951871216 cifn 0.6658119233325124 cifn 0.6712078689597547 cifn 0.6993865249678493 cifn 0.6907257186248899 cifn 0.7025954481214285 cifn 0.6975545780733228 cifn 0.7025852166116238 cifn 0.7097241440787911 cifn 0.8238312839530408 cifn 0.6661672578193247 ----------------------------------------------------------- loop_times 30_000_000.times{|e|} orig 1.0544864381663501 orig 1.4784484300762415 orig 1.0440643019974232 orig 1.4784217807464302 orig 1.3880611048080027 orig 1.1747447005473077 orig 1.2672417550347745 orig 1.1465763943269849 orig 1.143635923974216 orig 1.1028526439331472 cifn 1.40477504581213 cifn 1.1129847378470004 cifn 1.121070436667651 cifn 1.4712559906765819 cifn 1.1099597150459886 cifn 1.1987538286484778 cifn 1.0498235477134585 cifn 1.0789452488534153 cifn 1.1447957819327712 cifn 1.1127627361565828 ----------------------------------------------------------- loop_whileloop i = 0 while i<30_000_000 # benchmark loop 1 i += 1 end orig 0.502154887188226 orig 0.5063057141378522 orig 0.5042735310271382 orig 0.502301522064954 orig 0.53688899660483 orig 0.5540950410068035 orig 0.5562848839908838 orig 0.5126240896061063 orig 0.5162682989612222 orig 0.5194081449881196 cifn 0.5259133940562606 cifn 0.5073420433327556 cifn 0.5067124869674444 cifn 0.577549752779305 cifn 0.5310647338628769 cifn 0.507108370307833 cifn 0.5786277079023421 cifn 0.5911667658947408 cifn 0.5067441766150296 cifn 0.5212422548793256 ----------------------------------------------------------- loop_whileloop2 i = 0 while i< 6_000_000 # benchmark loop 2 i += 1 end orig 0.11641894606873393 orig 0.11657870374619961 orig 0.11589739331975579 orig 0.1165631739422679 orig 0.12738305609673262 orig 0.11621716385707259 orig 0.1163235567510128 orig 0.11595775000751019 orig 0.11633188603445888 orig 0.11627701483666897 cifn 0.11749357264488935 cifn 0.11791025288403034 cifn 0.11993265990167856 cifn 0.11734121292829514 cifn 0.11741786496713758 cifn 0.1176564609631896 cifn 0.11743593029677868 cifn 0.13107831589877605 cifn 0.11701310193166137 cifn 0.12972782785072923 ----------------------------------------------------------- securerandom require "securerandom" 20_0000.times do SecureRandom.random_number(100) end orig 0.6215345072560012 orig 0.6246511857025325 orig 0.6233846629038453 orig 0.6261124759912491 orig 0.6283445311710238 orig 0.6221050969325006 orig 0.6625714632682502 orig 0.6222124169580638 orig 0.633356565143913 orig 0.6230405392125249 cifn 0.625102651771158 cifn 0.6375593040138483 cifn 0.643527066335082 cifn 0.6361279748380184 cifn 0.6225220710039139 cifn 0.6355230142362416 cifn 0.6248127482831478 cifn 0.6284414483234286 cifn 0.6367243193089962 cifn 0.6219201949425042 ----------------------------------------------------------- so_ackermann #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ def ack(m, n) if m == 0 then n + 1 elsif n == 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end NUM = 9 ack(3, NUM) orig 0.5745902052149177 orig 0.5871808049269021 orig 0.5611909478902817 orig 0.6204588282853365 orig 0.554451443720609 orig 0.5594929112121463 orig 0.5530277262441814 orig 0.5535727548412979 orig 0.5528196231462061 orig 0.5652178889140487 cifn 0.5614550719037652 cifn 0.5558892698027194 cifn 0.5562013257294893 cifn 0.5548026622273028 cifn 0.5567596270702779 cifn 0.5576863610185683 cifn 0.5557813560590148 cifn 0.5541459750384092 cifn 0.5564689668826759 cifn 0.5589495711028576 ----------------------------------------------------------- so_array #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Paul Brannan and Mark Hubbart n = 9000 # Integer(ARGV.shift || 1) x = Array.new(n) y = Array.new(n, 0) n.times{|bi| x[bi] = bi + 1 } (0 .. 999).each do |e| (n-1).step(0,-1) do |bi| y[bi] += x.at(bi) end end # puts "#{y.first} #{y.last}" orig 0.7441649129614234 orig 0.7533640442416072 orig 0.7866768930107355 orig 0.7390182293020189 orig 0.7738386318087578 orig 0.8989356970414519 orig 0.7402352658100426 orig 0.7847985750995576 orig 0.7962804031558335 orig 0.8596923197619617 cifn 0.7681967657990754 cifn 0.7396648735739291 cifn 0.7461612639017403 cifn 0.7345957313664258 cifn 0.7358547863550484 cifn 0.7333027068525553 cifn 0.7345733880065382 cifn 0.734271083958447 cifn 0.7387689240276814 cifn 0.733971691224724 ----------------------------------------------------------- so_binary_trees # The Computer Language Shootout Benchmarks # http://shootout.alioth.debian.org # # contributed by Jesse Millikan # disable output alias puts_orig puts def puts str # disable puts end def item_check(tree) if tree[0] == nil tree[1] else tree[1] + item_check(tree[0]) - item_check(tree[2]) end end def bottom_up_tree(item, depth) if depth > 0 item_item = 2 * item depth -= 1 [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)] else [nil, item, nil] end end max_depth = 16 # ARGV[0].to_i min_depth = 4 max_depth = min_depth + 2 if min_depth + 2 > max_depth stretch_depth = max_depth + 1 stretch_tree = bottom_up_tree(0, stretch_depth) puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}" stretch_tree = nil long_lived_tree = bottom_up_tree(0, max_depth) min_depth.step(max_depth + 1, 2) do |depth| iterations = 2**(max_depth - depth + min_depth) check = 0 for i in 1..iterations temp_tree = bottom_up_tree(i, depth) check += item_check(temp_tree) temp_tree = bottom_up_tree(-i, depth) check += item_check(temp_tree) end puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}" end puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}" undef puts alias puts puts_orig orig 5.925883891992271 orig 6.120417619124055 orig 6.096665353979915 orig 6.0590095720253885 orig 6.23317896714434 orig 5.885848958045244 orig 5.915762994904071 orig 5.96832339791581 orig 5.959157692268491 orig 5.9340170389041305 cifn 5.898609424009919 cifn 5.8888295772485435 cifn 5.882803137879819 cifn 5.866172686219215 cifn 5.903348322026432 cifn 5.882569588255137 cifn 5.8573335646651685 cifn 5.858963703736663 cifn 5.883154528681189 cifn 5.868781893979758 ----------------------------------------------------------- so_concatenate #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # based on code from Aristarkh A Zagorodnikov and Dat Nguyen STUFF = "hello\n" i = 0 while i<10 i += 1 hello = '' 4_000_000.times do |e| hello << STUFF end end # puts hello.length orig 3.3319327062927186 orig 3.703483024146408 orig 3.2617122973315418 orig 3.423920346889645 orig 3.6855589989572763 orig 3.265596718993038 orig 3.2604052629321814 orig 3.2615202800370753 orig 3.527890140656382 orig 3.6738583077676594 cifn 4.300587580073625 cifn 3.5873061739839613 cifn 3.9445443833246827 cifn 3.2664203657768667 cifn 3.5507456050254405 cifn 4.141241214238107 cifn 3.2005881681106985 cifn 3.577665861696005 cifn 3.611433194950223 cifn 3.2949658357538283 ----------------------------------------------------------- so_count_words #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: wc-ruby.code,v 1.4 2004/11/13 07:43:32 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Paul Brannan input = open(File.join(File.dirname($0), 'wc.input'), 'rb') nl = nw = nc = 0 while true tmp = input.read(4096) or break data = tmp << (input.gets || "") nc += data.length nl += data.count("\n") ((data.strip! || data).tr!("\n", " ") || data).squeeze! nw += data.count(" ") + 1 end # STDERR.puts "#{nl} #{nw} #{nc}" orig 0.20976116694509983 orig 0.20798174710944295 orig 0.20921497885137796 orig 0.21097307279706 orig 0.2059275689534843 orig 0.2087845839560032 orig 0.2106038760393858 orig 0.2128308149985969 orig 0.21219895966351032 orig 0.21167484810575843 cifn 0.1979927821084857 cifn 0.1994414860382676 cifn 0.19886793987825513 cifn 0.19753705291077495 cifn 0.1974823963828385 cifn 0.19704748271033168 cifn 0.1973306848667562 cifn 0.19649820821359754 cifn 0.19790280191227794 cifn 0.19647452887147665 ----------------------------------------------------------- so_exception #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ $HI = 0 $LO = 0 NUM = 250000 # Integer(ARGV[0] || 1) class Lo_Exception < Exception def initialize(num) @value = num end end class Hi_Exception < Exception def initialize(num) @value = num end end def some_function(num) begin hi_function(num) rescue print "We shouldn't get here, exception is: #{$!.type}\n" end end def hi_function(num) begin lo_function(num) rescue Hi_Exception $HI = $HI + 1 end end def lo_function(num) begin blowup(num) rescue Lo_Exception $LO = $LO + 1 end end def blowup(num) if num % 2 == 0 raise Lo_Exception.new(num) else raise Hi_Exception.new(num) end end i = 1 max = NUM+1 while i < max i += 1 some_function(i+1) end orig 0.2665783278644085 orig 0.258524710778147 orig 0.26053433399647474 orig 0.25256265699863434 orig 0.2541483542881906 orig 0.2562246071174741 orig 0.25356854824349284 orig 0.2529876260086894 orig 0.33551212027668953 orig 0.27739742398262024 cifn 0.2498809420503676 cifn 0.2501554931513965 cifn 0.24985429691150784 cifn 0.25028866715729237 cifn 0.24953507678583264 cifn 0.2522261827252805 cifn 0.24960278859362006 cifn 0.25178121915087104 cifn 0.24983860459178686 cifn 0.24798526288941503 ----------------------------------------------------------- so_fannkuch # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura # Modified by Ryan Williams def fannkuch(n) maxFlips, m, r, check = 0, n-1, n, 0 count = (1..n).to_a perm = (1..n).to_a while true if check < 30 puts "#{perm}" check += 1 end while r != 1 count[r-1] = r r -= 1 end if perm[0] != 1 and perm[m] != n perml = perm.clone #.dup flips = 0 while (k = perml.first ) != 1 perml = perml.slice!(0, k).reverse + perml flips += 1 end maxFlips = flips if flips > maxFlips end while true if r==n then return maxFlips end perm.insert r,perm.shift break if (count[r] -= 1) > 0 r += 1 end end end def puts *args end N = 9 # (ARGV[0] || 1).to_i puts "Pfannkuchen(#{N}) = #{fannkuch(N)}" orig 0.9970462312921882 orig 1.009560514241457 orig 1.0268223229795694 orig 1.0453840079717338 orig 1.0108900237828493 orig 1.014922495931387 orig 1.013973408844322 orig 0.9925956930965185 orig 1.0255526369437575 orig 1.0035649612545967 cifn 0.9951937720179558 cifn 0.9876840189099312 cifn 0.9926991970278323 cifn 0.9943708330392838 cifn 1.007230042014271 cifn 0.991219743154943 cifn 1.0236665490083396 cifn 1.1376127931289375 cifn 0.9865791159681976 cifn 1.0060300277546048 ----------------------------------------------------------- so_fasta # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura $last = 42.0 def gen_random (max,im=139968,ia=3877,ic=29573) (max * ($last = ($last * ia + ic) % im)) / im end alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" iub = [ ["a", 0.27], ["c", 0.12], ["g", 0.12], ["t", 0.27], ["B", 0.02], ["D", 0.02], ["H", 0.02], ["K", 0.02], ["M", 0.02], ["N", 0.02], ["R", 0.02], ["S", 0.02], ["V", 0.02], ["W", 0.02], ["Y", 0.02], ] homosapiens = [ ["a", 0.3029549426680], ["c", 0.1979883004921], ["g", 0.1975473066391], ["t", 0.3015094502008], ] def make_repeat_fasta(id, desc, src, n) puts ">#{id} #{desc}" v = nil width = 60 l = src.length s = src * ((n / l) + 1) s.slice!(n, l) puts(s.scan(/.{1,#{width}}/).join("\n")) end def make_random_fasta(id, desc, table, n) puts ">#{id} #{desc}" rand, v = nil,nil width = 60 chunk = 1 * width prob = 0.0 table.each{|v| v[1]= (prob += v[1])} for i in 1..(n/width) puts((1..width).collect{ rand = gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end if n%width != 0 puts((1..(n%width)).collect{ rand = gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end end n = (ARGV[0] or 250_000).to_i make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2) make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3) make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5) orig 1.6356080891564488 orig 1.6369775529019535 orig 1.635192648973316 orig 1.638836617115885 orig 1.6391372387297451 orig 1.6395716439001262 orig 1.9610385540872812 orig 2.187157901003957 orig 1.636883128900081 orig 1.6765598030760884 cifn 1.6583037376403809 cifn 1.6849383651278913 cifn 1.629693961236626 cifn 1.6275359028950334 cifn 1.822131501045078 cifn 1.6325347889214754 cifn 1.630469092167914 cifn 1.6397383408620954 cifn 1.6683618552051485 cifn 1.7013376830145717 ----------------------------------------------------------- so_k_nucleotide # The Computer Language Shootout # http://shootout.alioth.debian.org # # contributed by jose fco. gonzalez # modified by Sokolov Yura seq = String.new def frecuency( seq,length ) n, table = seq.length - length + 1, Hash.new(0) f, i = nil, nil (0 ... length).each do |f| (f ... n).step(length) do |i| table[seq[i,length]] += 1 end end [n,table] end def sort_by_freq( seq,length ) n,table = frecuency( seq,length ) a, b, v = nil, nil, nil table.sort{|a,b| b[1] <=> a[1]}.each do |v| puts "%s %.3f" % [v[0].upcase,((v[1]*100).to_f/n)] end puts end def find_seq( seq,s ) n,table = frecuency( seq,s.length ) puts "#{table[s].to_s}\t#{s.upcase}" end input = open(File.join(File.dirname($0), 'fasta.output.100000'), 'rb') line = input.gets while line !~ /^>THREE/ line = input.gets while (line !~ /^>/) & line do seq << line.chomp line = input.gets end [1,2].each {|i| sort_by_freq( seq,i ) } %w(ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt).each{|s| find_seq( seq,s) } orig 1.0354255330748856 orig 1.0371576598845422 orig 1.0893553728237748 orig 1.0208638310432434 orig 1.0541560277342796 orig 1.3600142621435225 orig 1.5300938501022756 orig 1.0370798050425947 orig 1.1391361290588975 orig 1.041505039203912 cifn 1.0331966187804937 cifn 1.0413637328892946 cifn 1.0468915370292962 cifn 1.0602197027765214 cifn 1.0262628276832402 cifn 1.0324468710459769 cifn 1.0467809038236737 cifn 1.3318951642140746 cifn 1.08029326191172 cifn 1.4250411898829043 ----------------------------------------------------------- so_lists #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby NUM = 300 SIZE = 10000 def test_lists() # create a list of integers (Li1) from 1 to SIZE li1 = (1..SIZE).to_a # copy the list to li2 (not by individual items) li2 = li1.dup # remove each individual item from left side of li2 and # append to right side of li3 (preserving order) li3 = Array.new while (not li2.empty?) li3.push(li2.shift) end # li2 must now be empty # remove each individual item from right side of li3 and # append to right side of li2 (reversing list) while (not li3.empty?) li2.push(li3.pop) end # li3 must now be empty # reverse li1 in place li1.reverse! # check that first item is now SIZE if li1[0] != SIZE then p "not SIZE" 0 else # compare li1 and li2 for equality if li1 != li2 then return(0) else # return the length of the list li1.length end end end i = 0 while i LIMIT_SQUARED escape = true break end end byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1) bit_num += 1 # Code is very similar for these cases, but using separate blocks # ensures we skip the shifting when it's unnecessary, which is most cases. if (bit_num == 8) print byte_acc.chr byte_acc = 0 bit_num = 0 elsif (x == count_size) byte_acc <<= (8 - bit_num) print byte_acc.chr byte_acc = 0 bit_num = 0 end end end orig 2.0958151798695326 orig 2.780965874902904 orig 2.0064375759102404 orig 2.0610653329640627 orig 2.1120778978802264 orig 2.0586704341694713 orig 2.015258921775967 orig 2.1381753431633115 orig 2.1807910869829357 orig 2.6676320200785995 cifn 2.066858862992376 cifn 2.277603946160525 cifn 1.9915176262147725 cifn 2.1232695770449936 cifn 1.9864744101651013 cifn 1.9751482331193984 cifn 2.07661993522197 cifn 2.226917900145054 cifn 2.2135518323630095 cifn 1.9920973619446158 ----------------------------------------------------------- so_matrix #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ n = 60 #Integer(ARGV.shift || 1) size = 40 def mkmatrix(rows, cols) count = 1 mx = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| row[j] = count count += 1 end mx[bi] = row end mx end def mmult(rows, cols, m1, m2) m3 = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| val = 0 (0 .. (cols - 1)).each do |k| val += m1.at(bi).at(k) * m2.at(k).at(j) end row[j] = val end m3[bi] = row end m3 end m1 = mkmatrix(size, size) m2 = mkmatrix(size, size) mm = Array.new n.times do mm = mmult(size, size, m1, m2) end # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}" orig 0.5084648849442601 orig 0.49939578492194414 orig 0.5016013779677451 orig 0.4987873057834804 orig 0.5096689900383353 orig 0.49862795509397984 orig 0.5456731589511037 orig 0.5272655356675386 orig 0.5464846258983016 orig 0.5731147429905832 cifn 0.5242392169311643 cifn 0.5122245261445642 cifn 0.5046204780228436 cifn 0.523311410099268 cifn 0.5020718118175864 cifn 0.5087347952648997 cifn 0.5019351257942617 cifn 0.5006884480826557 cifn 0.506607233081013 cifn 0.558545630890876 ----------------------------------------------------------- so_meteor_contest #!/usr/bin/env ruby # # The Computer Language Shootout # http://shootout.alioth.debian.org # contributed by Kevin Barnes (Ruby novice) # PROGRAM: the main body is at the bottom. # 1) read about the problem here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ # 2) see how I represent a board as a bitmask by reading the blank_board comments # 3) read as your mental paths take you def print *args end # class to represent all information about a particular rotation of a particular piece class Rotation # an array (by location) containing a bit mask for how the piece maps at the given location. # if the rotation is invalid at that location the mask will contain false attr_reader :start_masks # maps a direction to a relative location. these differ depending on whether it is an even or # odd row being mapped from @@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 } @@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 } def initialize( directions ) @even_offsets, @odd_offsets = normalize_offsets( get_values( directions )) @even_mask = mask_for_offsets( @even_offsets) @odd_mask = mask_for_offsets( @odd_offsets) @start_masks = Array.new(60) # create the rotational masks by placing the base mask at the location and seeing if # 1) it overlaps the boundaries and 2) it produces a prunable board. if either of these # is true the piece cannot be placed 0.upto(59) do | offset | mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset) if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then imask = compute_required( mask, offset) @start_masks[offset] = [ mask, imask, imask | mask ] else @start_masks[offset] = false end end end def compute_required( mask, offset ) board = blank_board 0.upto(offset) { | i | board |= 1 << i } board |= mask return 0 if (!prunable(board | mask, offset)) board = flood_fill(board,58) count = 0 imask = 0 0.upto(59) do | i | if (board[i] == 0) then imask |= (1 << i) count += 1 end end (count > 0 && count < 5) ? imask : 0 end def flood_fill( board, location) return board if (board[location] == 1) board |= 1 << location row, col = location.divmod(6) board = flood_fill( board, location - 1) if (col > 0) board = flood_fill( board, location + 1) if (col < 4) if (row % 2 == 0) then board = flood_fill( board, location - 7) if (col > 0 && row > 0) board = flood_fill( board, location - 6) if (row > 0) board = flood_fill( board, location + 6) if (row < 9) board = flood_fill( board, location + 5) if (col > 0 && row < 9) else board = flood_fill( board, location - 5) if (col < 4 && row > 0) board = flood_fill( board, location - 6) if (row > 0) board = flood_fill( board, location + 6) if (row < 9) board = flood_fill( board, location + 7) if (col < 4 && row < 9) end board end # given a location, produces a list of relative locations covered by the piece at this rotation def offsets( location) if is_even( location) then @even_offsets.collect { | value | value + location } else @odd_offsets.collect { | value | value + location } end end # returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows) # this is hard to explain. imagine we have this partial board: # 0 0 0 0 0 x [positions 0-5] # 0 0 1 1 0 x [positions 6-11] # 0 0 1 0 0 x [positions 12-17] # 0 1 0 0 0 x [positions 18-23] # 0 1 0 0 0 x [positions 24-29] # 0 0 0 0 0 x [positions 30-35] # ... # The top-left of the piece is at position 8, the # board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that # sorted order. Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained # by subtracting 8 from everything. Now imagine the piece shifted up and to the right so it's on an even row: # 0 0 0 1 1 x [positions 0-5] # 0 0 1 0 0 x [positions 6-11] # 0 0 1 0 0 x [positions 12-17] # 0 1 0 0 0 x [positions 18-23] # 0 0 0 0 0 x [positions 24-29] # 0 0 0 0 0 x [positions 30-35] # ... # Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the # offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what # this function would return def normalize_offsets( values) min = values.min even_min = is_even(min) other_min = even_min ? min + 6 : min + 7 other_values = values.collect do | value | if is_even(value) then value + 6 - other_min else value + 7 - other_min end end values.collect! { | value | value - min } if even_min then [values, other_values] else [other_values, values] end end # produce a bitmask representation of an array of offset locations def mask_for_offsets( offsets ) mask = 0 offsets.each { | value | mask = mask + ( 1 << value ) } mask end # finds a "safe" position that a position as described by a list of directions can be placed # without falling off any edge of the board. the values returned a location to place the first piece # at so it will fit after making the described moves def start_adjust( directions ) south = east = 0; directions.each do | direction | east += 1 if ( direction == :sw || direction == :nw || direction == :west ) south += 1 if ( direction == :nw || direction == :ne ) end south * 6 + east end # given a set of directions places the piece (as defined by a set of directions) on the board at # a location that will not take it off the edge def get_values ( directions ) start = start_adjust(directions) values = [ start ] directions.each do | direction | if (start % 12 >= 6) then start += @@rotation_odd_adder[direction] else start += @@rotation_even_adder[direction] end values += [ start ] end # some moves take you back to an existing location, we'll strip duplicates values.uniq end end # describes a piece and caches information about its rotations to as to be efficient for iteration # ATTRIBUTES: # rotations -- all the rotations of the piece # type -- a numeic "name" of the piece # masks -- an array by location of all legal rotational masks (a n inner array) for that location # placed -- the mask that this piece was last placed at (not a location, but the actual mask used) class Piece attr_reader :rotations, :type, :masks attr_accessor :placed # transform hashes that change one direction into another when you either flip or rotate a set of directions @@flip_converter = { :west => :west, :east => :east, :nw => :sw, :ne => :se, :sw => :nw, :se => :ne } @@rotate_converter = { :west => :nw, :east => :se, :nw => :ne, :ne => :east, :sw => :west, :se => :sw } def initialize( directions, type ) @type = type @rotations = Array.new(); @map = {} generate_rotations( directions ) directions.collect! { | value | @@flip_converter[value] } generate_rotations( directions ) # creates the masks AND a map that returns [location, rotation] for any given mask # this is used when a board is found and we want to draw it, otherwise the map is unused @masks = Array.new(); 0.upto(59) do | i | even = true @masks[i] = @rotations.collect do | rotation | mask = rotation.start_masks[i] @map[mask[0]] = [ i, rotation ] if (mask) mask || nil end @masks[i].compact! end end # rotates a set of directions through all six angles and adds a Rotation to the list for each one def generate_rotations( directions ) 6.times do rotations.push( Rotation.new(directions)) directions.collect! { | value | @@rotate_converter[value] } end end # given a board string, adds this piece to the board at whatever location/rotation # important: the outbound board string is 5 wide, the normal location notation is six wide (padded) def fill_string( board_string) location, rotation = @map[@placed] rotation.offsets(location).each do | offset | row, col = offset.divmod(6) board_string[ row*5 + col, 1 ] = @type.to_s end end end # a blank bit board having this form: # # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 1 1 1 1 1 1 # # where left lest significant bit is the top left and the most significant is the lower right # the actual board only consists of the 0 places, the 1 places are blockers to keep things from running # off the edges or bottom def blank_board 0b111111100000100000100000100000100000100000100000100000100000100000 end def full_board 0b111111111111111111111111111111111111111111111111111111111111111111 end # determines if a location (bit position) is in an even row def is_even( location) (location % 12) < 6 end # support function that create three utility maps: # $converter -- for each row an array that maps a five bit row (via array mapping) # to the a a five bit representation of the bits below it # $bit_count -- maps a five bit row (via array mapping) to the number of 1s in the row # @@new_regions -- maps a five bit row (via array mapping) to an array of "region" arrays # a region array has three values the first is a mask of bits in the region, # the second is the count of those bits and the third is identical to the first # examples: # 0b10010 => [ 0b01100, 2, 0b01100 ], [ 0b00001, 1, 0b00001] # 0b01010 => [ 0b10000, 1, 0b10000 ], [ 0b00100, 1, 0b00100 ], [ 0b00001, 1, 0b00001] # 0b10001 => [ 0b01110, 3, 0b01110 ] def create_collector_support odd_map = [0b11, 0b110, 0b1100, 0b11000, 0b10000] even_map = [0b1, 0b11, 0b110, 0b1100, 0b11000] all_odds = Array.new(0b100000) all_evens = Array.new(0b100000) bit_counts = Array.new(0b100000) new_regions = Array.new(0b100000) 0.upto(0b11111) do | i | bit_count = odd = even = 0 0.upto(4) do | bit | if (i[bit] == 1) then bit_count += 1 odd |= odd_map[bit] even |= even_map[bit] end end all_odds[i] = odd all_evens[i] = even bit_counts[i] = bit_count new_regions[i] = create_regions( i) end $converter = [] 10.times { | row | $converter.push((row % 2 == 0) ? all_evens : all_odds) } $bit_counts = bit_counts $regions = new_regions.collect { | set | set.collect { | value | [ value, bit_counts[value], value] } } end # determines if a board is punable, meaning that there is no possibility that it # can be filled up with pieces. A board is prunable if there is a grouping of unfilled spaces # that are not a multiple of five. The following board is an example of a prunable board: # 0 0 1 0 0 # 0 1 0 0 0 # 1 1 0 0 0 # 0 1 0 0 0 # 0 0 0 0 0 # ... # # This board is prunable because the top left corner is only 3 bits in area, no piece will ever fit it # parameters: # board -- an initial bit board (6 bit padded rows, see blank_board for format) # location -- starting location, everything above and to the left is already full # slotting -- set to true only when testing initial pieces, when filling normally # additional assumptions are possible # # Algorithm: # The algorithm starts at the top row (as determined by location) and iterates a row at a time # maintainng counts of active open areas (kept in the collector array) each collector contains # three values at the start of an iteration: # 0: mask of bits that would be adjacent to the collector in this row # 1: the number of bits collected so far # 2: a scratch space starting as zero, but used during the computation to represent # the empty bits in the new row that are adjacent (position 0) # The exact procedure is described in-code def prunable( board, location, slotting = false) collectors = [] # loop across the rows (location / 6).to_i.upto(9) do | row_on | # obtain a set of regions representing the bits of the current row. regions = $regions[(board >> (row_on * 6)) & 0b11111] converter = $converter[row_on] # track the number of collectors at the start of the cycle so that # we don't compute against newly created collectors, only existing collectors initial_collector_count = collectors.length # loop against the regions. For each region of the row # we will see if it connects to one or more existing collectors. # if it connects to 1 collector, the bits from the region are added to the # bits of the collector and the mask is placed in collector[2] # If the region overlaps more than one collector then all the collectors # it overlaps with are merged into the first one (the others are set to nil in the array) # if NO collectors are found then the region is copied as a new collector regions.each do | region | collector_found = nil region_mask = region[2] initial_collector_count.times do | collector_num | collector = collectors[collector_num] if (collector) then collector_mask = collector[0] if (collector_mask & region_mask != 0) then if (collector_found) then collector_found[0] |= collector_mask collector_found[1] += collector[1] collector_found[2] |= collector[2] collectors[collector_num] = nil else collector_found = collector collector[1] += region[1] collector[2] |= region_mask end end end end if (collector_found == nil) then collectors.push(Array.new(region)) end end # check the existing collectors, if any collector overlapped no bits in the region its [2] value will # be zero. The size of any such reaason is tested if it is not a multiple of five true is returned since # the board is prunable. if it is a multiple of five it is removed. # Collector that are still active have a new adjacent value [0] set based n the matched bits # and have [2] cleared out for the next cycle. collectors.length.times do | collector_num | collector = collectors[collector_num] if (collector) then if (collector[2] == 0) then return true if (collector[1] % 5 != 0) collectors[collector_num] = nil else # if a collector matches all bits in the row then we can return unprunable early for the # following reasons: # 1) there can be no more unavailable bits bince we fill from the top left downward # 2) all previous regions have been closed or joined so only this region can fail # 3) this region must be good since there can never be only 1 region that is nuot # a multiple of five # this rule only applies when filling normally, so we ignore the rule if we are "slotting" # in pieces to see what configurations work for them (the only other time this algorithm is used). return false if (collector[2] == 0b11111 && !slotting) collector[0] = converter[collector[2]] collector[2] = 0 end end end # get rid of all the empty converters for the next round collectors.compact! end return false if (collectors.length <= 1) # 1 collector or less and the region is fine collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size end # creates a region given a row mask. see prunable for what a "region" is def create_regions( value ) regions = [] cur_region = 0 5.times do | bit | if (value[bit] == 0) then cur_region |= 1 << bit else if (cur_region != 0 ) then regions.push( cur_region) cur_region = 0; end end end regions.push(cur_region) if (cur_region != 0) regions end # find up to the counted number of solutions (or all solutions) and prints the final result def find_all find_top( 1) find_top( 0) print_results end # show the board def print_results print "#{@boards_found} solutions found\n\n" print_full_board( @min_board) print "\n" print_full_board( @max_board) print "\n" end # finds solutions. This special version of the main function is only used for the top level # the reason for it is basically to force a particular ordering on how the rotations are tested for # the first piece. It is called twice, first looking for placements of the odd rotations and then # looking for placements of the even locations. # # WHY? # Since any found solution has an inverse we want to maximize finding solutions that are not already found # as an inverse. The inverse will ALWAYS be 3 one of the piece configurations that is exactly 3 rotations away # (an odd number). Checking even vs odd then produces a higher probability of finding more pieces earlier # in the cycle. We still need to keep checking all the permutations, but our probability of finding one will # diminsh over time. Since we are TOLD how many to search for this lets us exit before checking all pieces # this bennifit is very great when seeking small numbers of solutions and is 0 when looking for more than the # maximum number def find_top( rotation_skip) board = blank_board (@pieces.length-1).times do piece = @pieces.shift piece.masks[0].each do | mask, imask, cmask | if ((rotation_skip += 1) % 2 == 0) then piece.placed = mask find( 1, 1, board | mask) end end @pieces.push(piece) end piece = @pieces.shift @pieces.push(piece) end # the normail find routine, iterates through the available pieces, checks all rotations at the current location # and adds any boards found. depth is acheived via recursion. the overall approach is described # here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ # parameters: # start_location -- where to start looking for place for the next piece at # placed -- number of pieces placed # board -- current state of the board # # see in-code comments def find( start_location, placed, board) # find the next location to place a piece by looking for an empty bit while board[start_location] == 1 start_location += 1 end @pieces.length.times do piece = @pieces.shift piece.masks[start_location].each do | mask, imask, cmask | if ( board & cmask == imask) then piece.placed = mask if (placed == 9) then add_board else find( start_location + 1, placed + 1, board | mask) end end end @pieces.push(piece) end end # print the board def print_full_board( board_string) 10.times do | row | print " " if (row % 2 == 1) 5.times do | col | print "#{board_string[row*5 + col,1]} " end print "\n" end end # when a board is found we "draw it" into a string and then flip that string, adding both to # the list (hash) of solutions if they are unique. def add_board board_string = "99999999999999999999999999999999999999999999999999" @all_pieces.each { | piece | piece.fill_string( board_string ) } save( board_string) save( board_string.reverse) end # adds a board string to the list (if new) and updates the current best/worst board def save( board_string) if (@all_boards[board_string] == nil) then @min_board = board_string if (board_string < @min_board) @max_board = board_string if (board_string > @max_board) @all_boards.store(board_string,true) @boards_found += 1 # the exit motif is a time saver. Ideally the function should return, but those tests # take noticeable time (performance). if (@boards_found == @stop_count) then print_results exit(0) end end end ## ## MAIN BODY :) ## create_collector_support @pieces = [ Piece.new( [ :nw, :ne, :east, :east ], 2), Piece.new( [ :ne, :se, :east, :ne ], 7), Piece.new( [ :ne, :east, :ne, :nw ], 1), Piece.new( [ :east, :sw, :sw, :se ], 6), Piece.new( [ :east, :ne, :se, :ne ], 5), Piece.new( [ :east, :east, :east, :se ], 0), Piece.new( [ :ne, :nw, :se, :east, :se ], 4), Piece.new( [ :se, :se, :se, :west ], 9), Piece.new( [ :se, :se, :east, :se ], 8), Piece.new( [ :east, :east, :sw, :se ], 3) ]; @all_pieces = Array.new( @pieces) @min_board = "99999999999999999999999999999999999999999999999999" @max_board = "00000000000000000000000000000000000000000000000000" @stop_count = ARGV[0].to_i || 2089 @all_boards = {} @boards_found = 0 find_all ######## DO IT!!! orig 2.5997486510314047 orig 2.604744188953191 orig 2.601611656136811 orig 2.7638453361578286 orig 2.6885851197876036 orig 2.66766708297655 orig 2.6044130688533187 orig 2.6164070828817785 orig 2.769185310229659 orig 2.6049088961444795 cifn 2.606008287984878 cifn 2.695201203227043 cifn 2.6049174717627466 cifn 3.0089910333044827 cifn 2.6238759919069707 cifn 2.64335690299049 cifn 2.6094042561016977 cifn 2.6594930877909064 cifn 2.6061786580830812 cifn 2.6446391083300114 ----------------------------------------------------------- so_nbody # The Computer Language Shootout # http://shootout.alioth.debian.org # # Optimized for Ruby by Jesse Millikan # From version ported by Michael Neumann from the C gcc version, # which was written by Christoph Bauer. SOLAR_MASS = 4 * Math::PI**2 DAYS_PER_YEAR = 365.24 def _puts *args end class Planet attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass def initialize(x, y, z, vx, vy, vz, mass) @x, @y, @z = x, y, z @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR @mass = mass * SOLAR_MASS end def move_from_i(bodies, nbodies, dt, i) while i < nbodies b2 = bodies[i] dx = @x - b2.x dy = @y - b2.y dz = @z - b2.z distance = Math.sqrt(dx * dx + dy * dy + dz * dz) mag = dt / (distance * distance * distance) b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag @vx -= dx * b2_mass_mag @vy -= dy * b2_mass_mag @vz -= dz * b2_mass_mag b2.vx += dx * b_mass_mag b2.vy += dy * b_mass_mag b2.vz += dz * b_mass_mag i += 1 end @x += dt * @vx @y += dt * @vy @z += dt * @vz end end def energy(bodies) e = 0.0 nbodies = bodies.size for i in 0 ... nbodies b = bodies[i] e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz) for j in (i + 1) ... nbodies b2 = bodies[j] dx = b.x - b2.x dy = b.y - b2.y dz = b.z - b2.z distance = Math.sqrt(dx * dx + dy * dy + dz * dz) e -= (b.mass * b2.mass) / distance end end e end def offset_momentum(bodies) px, py, pz = 0.0, 0.0, 0.0 for b in bodies m = b.mass px += b.vx * m py += b.vy * m pz += b.vz * m end b = bodies[0] b.vx = - px / SOLAR_MASS b.vy = - py / SOLAR_MASS b.vz = - pz / SOLAR_MASS end BODIES = [ # sun Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0), # jupiter Planet.new( 4.84143144246472090e+00, -1.16032004402742839e+00, -1.03622044471123109e-01, 1.66007664274403694e-03, 7.69901118419740425e-03, -6.90460016972063023e-05, 9.54791938424326609e-04), # saturn Planet.new( 8.34336671824457987e+00, 4.12479856412430479e+00, -4.03523417114321381e-01, -2.76742510726862411e-03, 4.99852801234917238e-03, 2.30417297573763929e-05, 2.85885980666130812e-04), # uranus Planet.new( 1.28943695621391310e+01, -1.51111514016986312e+01, -2.23307578892655734e-01, 2.96460137564761618e-03, 2.37847173959480950e-03, -2.96589568540237556e-05, 4.36624404335156298e-05), # neptune Planet.new( 1.53796971148509165e+01, -2.59193146099879641e+01, 1.79258772950371181e-01, 2.68067772490389322e-03, 1.62824170038242295e-03, -9.51592254519715870e-05, 5.15138902046611451e-05) ] init = 200_000 # ARGV[0] n = Integer(init) offset_momentum(BODIES) puts "%.9f" % energy(BODIES) nbodies = BODIES.size dt = 0.01 n.times do i = 0 while i < nbodies b = BODIES[i] b.move_from_i(BODIES, nbodies, dt, i + 1) i += 1 end end puts "%.9f" % energy(BODIES) orig 2.0072798719629645 orig 1.3614898859523237 orig 1.9756145821884274 orig 1.2214680379256606 orig 1.2605976480990648 orig 1.2258230750449002 orig 1.2312483042478561 orig 1.2405893998220563 orig 1.2265848140232265 orig 1.3755623488686979 cifn 1.6869093882851303 cifn 1.194847539998591 cifn 1.1867954772897065 cifn 1.3812363352626562 cifn 1.1890067751519382 cifn 1.185186909046024 cifn 1.183205250184983 cifn 1.1860871510580182 cifn 1.3984458483755589 cifn 1.1835683416575193 ----------------------------------------------------------- so_nested_loop #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # from Avi Bryant n = 16 # Integer(ARGV.shift || 1) x = 0 n.times do n.times do n.times do n.times do n.times do n.times do x += 1 end end end end end end # puts x orig 0.9310078108683228 orig 0.9285220829769969 orig 0.927584889344871 orig 0.9255598257295787 orig 0.9384913379326463 orig 0.9288485771976411 orig 0.9427085788920522 orig 0.9258314170874655 orig 0.93180031189695 orig 0.9339788421057165 cifn 0.9189866129308939 cifn 0.9229211281053722 cifn 1.0670786811970174 cifn 1.0914216456003487 cifn 1.1704948521219194 cifn 1.060001299250871 cifn 1.0704133231192827 cifn 0.9191121268086135 cifn 0.9221872068010271 cifn 0.9854744942858815 ----------------------------------------------------------- so_nsieve # The Computer Language Shootout # http://shootout.alioth.debian.org/ # # contributed by Glenn Parker, March 2005 # modified by Evan Phoenix, Sept 2006 def sieve(m) flags = Flags.dup[0,m] count = 0 pmax = m - 1 p = 2 while p <= pmax unless flags[p].zero? count += 1 mult = p while mult <= pmax flags[mult] = 0 mult += p end end p += 1 end count end n = 9 # (ARGV[0] || 2).to_i Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*") n.downto(n-2) do |exponent| break if exponent < 0 m = (1 << exponent) * 10_000 # m = (2 ** exponent) * 10_000 count = sieve(m) printf "Primes up to %8d %8d\n", m, count end orig 1.555606087204069 orig 1.443027424160391 orig 1.4537333310581744 orig 1.4668210158124566 orig 1.4543937630951405 orig 1.4452641061507165 orig 1.4433491779491305 orig 1.456248882226646 orig 1.4484401801601052 orig 1.5194945991970599 cifn 1.4508943753316998 cifn 1.5573540199548006 cifn 1.466377183329314 cifn 1.4548259088769555 cifn 1.4684453010559082 cifn 1.4467292418703437 cifn 1.4481982211582363 cifn 1.450239596888423 cifn 1.4408685863018036 cifn 1.4606604189611971 ----------------------------------------------------------- so_nsieve_bits #!/usr/bin/ruby #coding: us-ascii # # The Great Computer Language Shootout # http://shootout.alioth.debian.org/ # # nsieve-bits in Ruby # Contributed by Glenn Parker, March 2005 CharExponent = 3 BitsPerChar = 1 << CharExponent LowMask = BitsPerChar - 1 def sieve(m) items = "\xFF" * ((m / BitsPerChar) + 1) masks = "" BitsPerChar.times do |b| masks << (1 << b).chr end count = 0 pmax = m - 1 2.step(pmax, 1) do |p| if items[p >> CharExponent][p & LowMask] == 1 count += 1 p.step(pmax, p) do |mult| a = mult >> CharExponent b = mult & LowMask items[a] -= masks[b] if items[a][b] != 0 end end end count end n = 9 # (ARGV[0] || 2).to_i n.step(n - 2, -1) do |exponent| break if exponent < 0 m = 2 ** exponent * 10_000 count = sieve(m) printf "Primes up to %8d %8d\n", m, count end orig 1.9278284320607781 orig 2.100152346305549 orig 1.9733858779072762 orig 2.092970001976937 orig 1.9148268811404705 orig 2.1474569044075906 orig 1.931476964149624 orig 1.9160348046571016 orig 1.9160951562225819 orig 1.9562418996356428 cifn 1.9019712000153959 cifn 1.9014005670323968 cifn 1.888387938030064 cifn 1.9108130717650056 cifn 2.044906832743436 cifn 1.9093922302126884 cifn 1.9582507819868624 cifn 1.9447822510264814 cifn 1.9422923331148922 cifn 1.89353541797027 ----------------------------------------------------------- so_object #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Aristarkh Zagorodnikov class Toggle def initialize(start_state) @bool = start_state end def value @bool end def activate @bool = !@bool self end end class NthToggle < Toggle def initialize(start_state, max_counter) super start_state @count_max = max_counter @counter = 0 end def activate @counter += 1 if @counter >= @count_max @bool = !@bool @counter = 0 end self end end n = 1500000 # (ARGV.shift || 1).to_i toggle = Toggle.new 1 5.times do toggle.activate.value ? 'true' : 'false' end n.times do toggle = Toggle.new 1 end ntoggle = NthToggle.new 1, 3 8.times do ntoggle.activate.value ? 'true' : 'false' end n.times do ntoggle = NthToggle.new 1, 3 end orig 0.5967604811303318 orig 0.5960046811960638 orig 0.8839727439917624 orig 0.6393470773473382 orig 0.6462632799521089 orig 0.6685686856508255 orig 0.6879963483661413 orig 0.5966092050075531 orig 0.5980434771627188 orig 0.5961526231840253 cifn 0.5980577850714326 cifn 0.5975311961956322 cifn 0.598563876003027 cifn 0.5982441152445972 cifn 0.6217541238293052 cifn 0.6260208962485194 cifn 0.6710311518982053 cifn 0.6658022291958332 cifn 0.6335182720795274 cifn 0.9560786592774093 ----------------------------------------------------------- so_partial_sums n = 2_500_000 # (ARGV.shift || 1).to_i alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0 1.upto(n) do |d| d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d) s0 += (2.0 / 3.0) ** (d - 1.0) s1 += 1.0 / Math.sqrt(d) s2 += 1.0 / (d * (d + 1.0)) s3 += 1.0 / (d3 * ds * ds) s4 += 1.0 / (d3 * dc * dc) s5 += 1.0 / d s6 += 1.0 / d2 s7 += alt / d s8 += alt / (2.0 * d - 1.0) alt = -alt end if false printf("%.9f\t(2/3)^k\n", s0) printf("%.9f\tk^-0.5\n", s1) printf("%.9f\t1/k(k+1)\n", s2) printf("%.9f\tFlint Hills\n", s3) printf("%.9f\tCookson Hills\n", s4) printf("%.9f\tHarmonic\n", s5) printf("%.9f\tRiemann Zeta\n", s6) printf("%.9f\tAlternating Harmonic\n", s7) printf("%.9f\tGregory\n", s8) end orig 1.9752218620851636 orig 1.9119413942098618 orig 1.778201603796333 orig 1.7599895298480988 orig 1.7614377411082387 orig 1.833109196741134 orig 1.856398533564061 orig 1.7600028258748353 orig 1.761487582232803 orig 1.7662914898246527 cifn 1.7463637958280742 cifn 1.770708974916488 cifn 1.730032138992101 cifn 1.7560259751044214 cifn 1.7359126550145447 cifn 1.7710459670051932 cifn 1.7311464319936931 cifn 1.7322282292880118 cifn 1.791019894182682 cifn 1.802270052023232 ----------------------------------------------------------- so_pidigits # The Great Computer Language Shootout # http://shootout.alioth.debian.org/ # # contributed by Gabriele Renzi class PiDigitSpigot def initialize() @z = Transformation.new 1,0,0,1 @x = Transformation.new 0,0,0,0 @inverse = Transformation.new 0,0,0,0 end def next! @y = @z.extract(3) if safe? @y @z = produce(@y) @y else @z = consume @x.next!() next!() end end def safe?(digit) digit == @z.extract(4) end def produce(i) @inverse.qrst(10,-10*i,0,1).compose(@z) end def consume(a) @z.compose(a) end end class Transformation attr_reader :q, :r, :s, :t def initialize (q, r, s, t) @q,@r,@s,@t,@k = q,r,s,t,0 end def next!() @q = @k = @k + 1 @r = 4 * @k + 2 @s = 0 @t = 2 * @k + 1 self end def extract(j) (@q * j + @r) / (@s * j + @t) end def compose(a) self.class.new( @q * a.q, @q * a.r + r * a.t, @s * a.q + t * a.s, @s * a.r + t * a.t ) end def qrst *args initialize *args self end end WIDTH = 10 n = 2_500 # Integer(ARGV[0]) j = 0 digits = PiDigitSpigot.new while n > 0 if n >= WIDTH WIDTH.times {print digits.next!} j += WIDTH else n.times {print digits.next!} (WIDTH-n).times {print " "} j += n end puts "\t:"+j.to_s n -= WIDTH end orig 0.9291856721974909 orig 0.9316839911043644 orig 0.9313547620549798 orig 0.933560177218169 orig 0.9309126697480679 orig 0.9320342419669032 orig 0.9325613020919263 orig 0.9307575630955398 orig 0.9314228482544422 orig 0.9297448340803385 cifn 0.926803327165544 cifn 0.9251373182050884 cifn 0.9252712689340115 cifn 0.9267899598926306 cifn 0.9265353158116341 cifn 0.9279667525552213 cifn 0.9242296731099486 cifn 0.9272476257756352 cifn 0.9258163650520146 cifn 0.92583869677037 ----------------------------------------------------------- so_random # from http://www.bagley.org/~doug/shootout/bench/random/random.ruby IM = 139968.0 IA = 3877.0 IC = 29573.0 $last = 42.0 def gen_random(max) (max * ($last = ($last * IA + IC) % IM)) / IM end N = 3_000_000 i = 0 while i/ if seq.length != 0 revcomp(seq.join) seq=Array.new end puts $_ else $_.sub(/\n/,'') seq.push $_ end end revcomp(seq.join) orig 1.0257664220407605 orig 1.0240043583326042 orig 1.0204119519330561 orig 1.0245320750400424 orig 1.0242436858825386 orig 1.0295845181681216 orig 1.0237023220397532 orig 1.0226512770168483 orig 1.0203461139462888 orig 1.021104162093252 cifn 1.0392583478242159 cifn 1.1048204898834229 cifn 1.0508310538716614 cifn 1.0292779561132193 cifn 1.0345519999973476 cifn 1.1420279797166586 cifn 1.2805973198264837 cifn 1.069091112818569 cifn 1.1466383300721645 cifn 1.2220607441850007 ----------------------------------------------------------- so_sieve # from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby num = 500 count = i = j = 0 flags0 = Array.new(8192,1) k = 0 while k < num k += 1 count = 0 flags = flags0.dup i = 2 while i<8192 i += 1 if flags[i] # remove all multiples of prime: i j = i*i while j < 8192 j += i flags[j] = nil end count += 1 end end end count orig 0.46708559710532427 orig 0.4674626961350441 orig 0.4654919053427875 orig 0.4831028529442847 orig 0.665624663233757 orig 0.46632616594433784 orig 0.46571223391219974 orig 0.4663516068831086 orig 0.4664533128961921 orig 0.47622670512646437 cifn 0.7701801010407507 cifn 0.46277670515701175 cifn 0.46283111022785306 cifn 0.4657683987170458 cifn 0.47000441793352365 cifn 0.4834646093659103 cifn 0.4629332721233368 cifn 0.4707829118706286 cifn 0.4779801550321281 cifn 0.4654649836011231 ----------------------------------------------------------- so_spectralnorm # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura def eval_A(i,j) return 1.0/((i+j)*(i+j+1)/2+i+1) end def eval_A_times_u(u) v, i = nil, nil (0..u.length-1).collect { |i| v = 0 for j in 0..u.length-1 v += eval_A(i,j)*u[j] end v } end def eval_At_times_u(u) v, i = nil, nil (0..u.length-1).collect{|i| v = 0 for j in 0..u.length-1 v += eval_A(j,i)*u[j] end v } end def eval_AtA_times_u(u) return eval_At_times_u(eval_A_times_u(u)) end n = 500 # ARGV[0].to_i u=[1]*n for i in 1..10 v=eval_AtA_times_u(u) u=eval_AtA_times_u(v) end vBv=0 vv=0 for i in 0..n-1 vBv += u[i]*v[i] vv += v[i]*v[i] end str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n" # print str orig 2.106372556183487 orig 1.972957578022033 orig 1.8773954850621521 orig 2.020125256385654 orig 1.8817815189249814 orig 1.9837470049969852 orig 1.9576541427522898 orig 1.9140302310697734 orig 1.8388473852537572 orig 1.893592240754515 cifn 1.8470528349280357 cifn 1.8193382010795176 cifn 2.1815854511223733 cifn 2.0830905297771096 cifn 1.868696722202003 cifn 2.2559291338548064 cifn 2.472355954349041 cifn 1.7722933068871498 cifn 2.0733507121913135 cifn 1.8700441252440214 ----------------------------------------------------------- vm1_attr_ivar class C attr_reader :a, :b def initialize @a = nil @b = nil end end obj = C.new i = 0 while i<30_000_000 # while loop 1 i += 1 j = obj.a k = obj.b end orig 1.2378051117993891 orig 1.1863559847697616 orig 1.2763529368676245 orig 1.4171733888797462 orig 1.0847719749435782 orig 1.1055887676775455 orig 1.0852194959297776 orig 1.0846103830263019 orig 1.0849137008190155 orig 1.084613642655313 cifn 1.1033361949957907 cifn 1.1189804240129888 cifn 1.1012849160470068 cifn 1.1021917718462646 cifn 1.1091181691735983 cifn 1.1050040530972183 cifn 1.1011933498084545 cifn 1.1007337593473494 cifn 1.1109465742483735 cifn 1.1009295168332756 ----------------------------------------------------------- vm1_attr_ivar_set class C attr_accessor :a, :b def initialize @a = nil @b = nil end end obj = C.new i = 0 while i<30_000_000 # while loop 1 i += 1 obj.a = 1 obj.b = 2 end orig 1.4065481908619404 orig 1.4122787741944194 orig 1.4122499041259289 orig 1.4236960699781775 orig 1.406699188053608 orig 1.4500929536297917 orig 1.5379198910668492 orig 1.5310789784416556 orig 1.5043558119796216 orig 1.5310157551430166 cifn 1.4246073248796165 cifn 1.549370301887393 cifn 1.6712343380786479 cifn 1.8218015409074724 cifn 1.5650880872271955 cifn 1.5356937069445848 cifn 1.4882569648325443 cifn 1.6790508669801056 cifn 1.4188502170145512 cifn 1.5609784140251577 ----------------------------------------------------------- vm1_block def m yield end i = 0 while i<30_000_000 # while loop 1 i += 1 m{ } end orig 2.5150674511678517 orig 2.083933950867504 orig 2.2310477383434772 orig 2.868125199805945 orig 2.1693601929582655 orig 2.118193901143968 orig 2.0132990293204784 orig 1.990195277146995 orig 1.9818290718831122 orig 1.9848649059422314 cifn 2.812289767898619 cifn 2.4634944391436875 cifn 2.1453674086369574 cifn 2.2855781042017043 cifn 2.095208860002458 cifn 2.107536536641419 cifn 2.0132446931675076 cifn 2.0015851967036724 cifn 2.0341987581923604 cifn 2.0969926244579256 ----------------------------------------------------------- vm1_const Const = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = Const k = Const end orig 0.7239595921710134 orig 0.7363717989064753 orig 0.8313595410436392 orig 0.7235521608963609 orig 0.7369474549777806 orig 0.9444801788777113 orig 0.7720829700119793 orig 0.8782983375713229 orig 0.7205003299750388 orig 0.7296159439720213 cifn 0.723568941000849 cifn 0.7228091289289296 cifn 0.7693799277767539 cifn 0.7660586959682405 cifn 0.8880357197485864 cifn 0.7544547370634973 cifn 0.7424733280204237 cifn 0.7918421677313745 cifn 0.7456487729214132 cifn 0.7235144712030888 ----------------------------------------------------------- vm1_ensure i = 0 while i<30_000_000 # benchmark loop 1 i += 1 begin begin ensure end ensure end end orig 0.5931683112867177 orig 0.529502912890166 orig 0.6311499662697315 orig 0.5617946581915021 orig 0.5926298112608492 orig 0.6760237640701234 orig 0.5739421546459198 orig 0.557015405036509 orig 0.6392816919833422 orig 0.5519614079967141 cifn 0.528540728148073 cifn 0.5442576352506876 cifn 0.508088675327599 cifn 0.5093850558623672 cifn 0.530520549044013 cifn 0.5087800449691713 cifn 0.544160314835608 cifn 0.5610186420381069 cifn 0.5189141132868826 cifn 0.7078372524119914 ----------------------------------------------------------- vm1_float_simple i = 0.0; f = 0.0 while i<30_000_000 i += 1 f += 0.1; f -= 0.1 f += 0.1; f -= 0.1 f += 0.1; f -= 0.1 end orig 4.690291976090521 orig 4.7215284877456725 orig 5.16697398526594 orig 5.085578074213117 orig 4.829474919009954 orig 4.634848796762526 orig 4.757860891055316 orig 4.617943646851927 orig 4.761535393074155 orig 5.000541444867849 cifn 4.804011560045183 cifn 4.99983707210049 cifn 4.909150194842368 cifn 4.434188197832555 cifn 4.626325986813754 cifn 5.0894706337712705 cifn 4.3831794410943985 cifn 4.392079886980355 cifn 4.382117556408048 cifn 4.361418957822025 ----------------------------------------------------------- vm1_gc_short_lived i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end orig 9.304509398993105 orig 9.676180699840188 orig 9.476103235967457 orig 9.374175623990595 orig 9.309601012151688 orig 9.534369742963463 orig 9.447138806339353 orig 9.97854959918186 orig 9.50131467403844 orig 9.306530344765633 cifn 8.478051708079875 cifn 8.435939664952457 cifn 8.534058595076203 cifn 8.45220245514065 cifn 8.893704559653997 cifn 8.669548669829965 cifn 8.772625979036093 cifn 8.730521756224334 cifn 8.855933167040348 cifn 9.058392196893692 ----------------------------------------------------------- vm1_gc_short_with_complex_long def nested_hash h, n if n == 0 '' else 10.times{ h[Object.new] = nested_hash(h, n-1) } end end long_lived = Hash.new nested_hash long_lived, 6 GC.start GC.start i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end orig 11.243368465919048 orig 12.052865365054458 orig 11.530026246793568 orig 11.210451361257583 orig 11.15211952617392 orig 11.628066014032811 orig 11.225203857757151 orig 11.268672982696444 orig 11.18199091590941 orig 11.156729779671878 cifn 10.40848070429638 cifn 10.299369757063687 cifn 10.30003154790029 cifn 10.250937337055802 cifn 10.222193884663284 cifn 10.215804541949183 cifn 10.304469886235893 cifn 10.357694916892797 cifn 10.459618818946183 cifn 10.30885352473706 ----------------------------------------------------------- vm1_gc_short_with_long long_lived = Array.new(1_000_000){|i| "#{i}"} GC.start GC.start i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end orig 10.354676111601293 orig 10.180727440863848 orig 10.555785147007555 orig 10.505109495017678 orig 10.31462425738573 orig 11.117889564018697 orig 10.473215275909752 orig 10.299432866740972 orig 10.14588733902201 orig 10.259960202034563 cifn 9.576884679030627 cifn 9.407005771063268 cifn 9.684320336673409 cifn 9.361194126773626 cifn 9.402094163000584 cifn 9.342056245077401 cifn 9.726925035007298 cifn 9.50016016094014 cifn 9.826587522402406 cifn 9.96125561511144 ----------------------------------------------------------- vm1_gc_short_with_symbol # make many symbols 50_000.times{|i| sym = "sym#{i}".to_sym} GC.start GC.start i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end orig 9.735411474015564 orig 9.829395975917578 orig 9.659895056858659 orig 10.051136708818376 orig 9.923583627678454 orig 9.883695712313056 orig 9.819849140010774 orig 9.684469528961927 orig 9.778367101214826 orig 9.608096127863973 cifn 8.885723751969635 cifn 9.05120978411287 cifn 9.060404046904296 cifn 9.153172877151519 cifn 8.792820637114346 cifn 8.789532230701298 cifn 8.944240203127265 cifn 9.00537833198905 cifn 8.754713519010693 cifn 8.774518500082195 ----------------------------------------------------------- vm1_gc_wb_ary long_lived = [] GC.start GC.start i = 0 short_lived = '' while i<30_000_000 # while loop 1 long_lived[0] = short_lived # write barrier i+=1 end orig 1.064972945023328 orig 1.1278829099610448 orig 1.0825342261232436 orig 1.1078853788785636 orig 1.1670142351649702 orig 1.0700755110010505 orig 1.0652162488549948 orig 1.0805646772496402 orig 1.0698378621600568 orig 1.0759969879873097 cifn 1.1248177862726152 cifn 1.0859124651178718 cifn 1.084074430167675 cifn 1.1741821579635143 cifn 1.1255766400136054 cifn 1.1282922560349107 cifn 1.0985857010819018 cifn 1.083302142098546 cifn 1.1241898769512773 cifn 1.1163008692674339 ----------------------------------------------------------- vm1_gc_wb_obj class C attr_accessor :foo end long_lived = C.new GC.start GC.start i = 0 short_lived = '' while i<30_000_000 # while loop 1 long_lived.foo = short_lived # write barrier i+=1 end orig 1.0531753860414028 orig 1.0531366430222988 orig 1.2160639236681163 orig 1.3014375008642673 orig 1.0971353258937597 orig 1.1177513292059302 orig 1.5304826251231134 orig 1.1352369752712548 orig 1.2104359320364892 orig 1.0526812388561666 cifn 1.0647492189891636 cifn 1.1111031179316342 cifn 1.7122060428373516 cifn 1.0603405637666583 cifn 1.0614636330865324 cifn 1.059476898983121 cifn 1.0607658219523728 cifn 1.0605642488226295 cifn 1.0719398590736091 cifn 1.063098388724029 ----------------------------------------------------------- vm1_ivar @a = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = @a k = @a end orig 0.7430912400595844 orig 0.7431285078637302 orig 0.742898506578058 orig 0.7437271769158542 orig 0.7434191918000579 orig 0.7429712931625545 orig 0.7451320006512105 orig 0.7429601610638201 orig 0.7429621610790491 orig 0.7465186500921845 cifn 0.7447159737348557 cifn 0.7450704290531576 cifn 0.9019560869783163 cifn 0.7466467102058232 cifn 0.7451651869341731 cifn 0.7452071392908692 cifn 0.7448066486977041 cifn 0.7452165889553726 cifn 0.7454428509809077 cifn 0.7450726730749011 ----------------------------------------------------------- vm1_ivar_set i = 0 while i<30_000_000 # while loop 1 i += 1 @a = 1 @b = 2 end orig 0.8611529683694243 orig 0.8633321886882186 orig 0.860776440706104 orig 0.860536219086498 orig 0.8607435058802366 orig 0.8600738500244915 orig 0.88517288537696 orig 0.8746950756758451 orig 0.8776455237530172 orig 0.926747317891568 cifn 0.9713077279739082 cifn 0.8749902467243373 cifn 0.9644390041939914 cifn 0.8770898669026792 cifn 0.9039004580117762 cifn 0.9930688580498099 cifn 0.8687666007317603 cifn 0.8638944802805781 cifn 1.0594479879364371 cifn 0.9565139701589942 ----------------------------------------------------------- vm1_length a = 'abc' b = [1, 2, 3] i = 0 while i<30_000_000 # while loop 1 i += 1 a.length b.length end orig 0.9199405801482499 orig 1.0815521790646017 orig 0.9203274580650032 orig 0.9203438451513648 orig 0.9193168128840625 orig 0.9226081650704145 orig 0.9184423657134175 orig 0.9185065510682762 orig 0.9262262936681509 orig 0.9184034373611212 cifn 0.9197465381585062 cifn 0.9226084309630096 cifn 0.9264897387474775 cifn 0.919222170021385 cifn 0.919735690113157 cifn 0.9199375100433826 cifn 0.9192307642661035 cifn 0.9189907419495285 cifn 0.9197675930336118 cifn 0.9201925578527153 ----------------------------------------------------------- vm1_lvar_init def m v unless v # unreachable code v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = v10 = v11 = v12 = v13 = v14 = v15 = v16 = v17 = v18 = v19 = v20 = v21 = v22 = v23 = v24 = v25 = v26 = v27 = v28 = v29 = v30 = v31 = v32 = v33 = v34 = v35 = v36 = v37 = v38 = v39 = v40 = v41 = v42 = v43 = v44 = v45 = v46 = v47 = v48 = v49 = v50 = 1 end end i = 0 while i<30_000_000 # while loop 1 i += 1 m i end orig 1.6971285957843065 orig 1.6933504207991064 orig 1.6937196222133934 orig 1.799639587290585 orig 1.7627710620872676 orig 1.6945214970037341 orig 1.7221799748949707 orig 1.7176085310056806 orig 1.7310869982466102 orig 1.7632625848054886 cifn 1.7341127158142626 cifn 1.8550323038361967 cifn 1.7142396760173142 cifn 1.7453877879306674 cifn 2.329875365830958 cifn 1.7227790732868016 cifn 1.7096748226322234 cifn 1.7110137278214097 cifn 1.9148883139714599 cifn 1.784229677170515 ----------------------------------------------------------- vm1_lvar_set i = 0 while i<30_000_000 # while loop 1 i += 1 a = b = c = d = e = f = g = h = j = k = l = m = n = o = p = q = r = 1 end orig 2.5127027672715485 orig 2.475254314020276 orig 2.4756750757806003 orig 2.4883634718135 orig 2.473931072279811 orig 2.4756014328449965 orig 2.4783511236310005 orig 2.4888984141871333 orig 2.4936251998879015 orig 2.4905885732732713 cifn 2.587305875029415 cifn 2.548610158264637 cifn 2.6099632368423045 cifn 2.53475900599733 cifn 2.4732128879986703 cifn 2.472559073008597 cifn 2.4715521689504385 cifn 2.4719378277659416 cifn 2.472903726156801 cifn 2.473940335214138 ----------------------------------------------------------- vm1_neq i = 0 obj1 = Object.new obj2 = Object.new while i<30_000_000 # while loop 1 i += 1 obj1 != obj2 end orig 0.9737011673860252 orig 0.9617538438178599 orig 0.9512727321125567 orig 0.9544897489249706 orig 0.9542389959096909 orig 0.9542329669930041 orig 0.9542968990281224 orig 0.9821862182579935 orig 0.9574981676414609 orig 0.9733665362000465 cifn 1.0171635099686682 cifn 0.9590452509000897 cifn 0.9638585983775556 cifn 0.9717954937368631 cifn 0.9626644859090447 cifn 0.984212813898921 cifn 0.958154484629631 cifn 0.962294118013233 cifn 1.0048646852374077 cifn 0.9959677131846547 ----------------------------------------------------------- vm1_not i = 0 obj = Object.new while i<30_000_000 # while loop 1 i += 1 !obj end orig 0.7752787168137729 orig 0.8527020118199289 orig 0.7487189969979227 orig 0.7482664277777076 orig 0.8328748550266027 orig 0.7828954462893307 orig 0.7515391800552607 orig 0.7484343387186527 orig 0.7597018689848483 orig 0.937969233840704 cifn 0.7488158908672631 cifn 0.772217744961381 cifn 0.7481847777962685 cifn 0.7482991050928831 cifn 0.7475586561486125 cifn 0.7477628658525646 cifn 0.7475665411911905 cifn 0.747989843133837 cifn 0.7478919699788094 cifn 0.7476043258793652 ----------------------------------------------------------- vm1_rescue i = 0 while i<30_000_000 # while loop 1 i += 1 begin rescue end end orig 0.6121684913523495 orig 0.6124492823146284 orig 0.6125382799655199 orig 0.6233169310726225 orig 0.6123274718411267 orig 0.6120016160421073 orig 0.6120005040429533 orig 0.6122152120806277 orig 0.6119551649317145 orig 0.6121033551171422 cifn 0.6113630859181285 cifn 0.6240996140986681 cifn 0.6105966079048812 cifn 0.6112003237940371 cifn 0.611084477044642 cifn 0.6105834101326764 cifn 0.6112210140563548 cifn 0.6108423327095807 cifn 0.610583723988384 cifn 0.6111214770935476 ----------------------------------------------------------- vm1_simplereturn def m return 1 end i = 0 while i<30_000_000 # while loop 1 i += 1 m end orig 1.234728857409209 orig 1.2207316271960735 orig 1.2301050028763711 orig 1.2597191571258008 orig 1.2185695301741362 orig 1.2189866229891777 orig 1.3231139229610562 orig 1.2195538049563766 orig 1.2504035928286612 orig 1.2456478318199515 cifn 1.2536466238088906 cifn 1.2688877689652145 cifn 1.4434076738543808 cifn 1.5051626092754304 cifn 1.2248552050441504 cifn 1.2466229498386383 cifn 1.3376020938158035 cifn 1.2865655208006501 cifn 1.438140963204205 cifn 1.3391848970204592 ----------------------------------------------------------- vm1_swap a = 1 b = 2 i = 0 while i<30_000_000 # while loop 1 i += 1 a, b = b, a end orig 0.7530540069565177 orig 0.7345694000832736 orig 0.7269428609870374 orig 0.7273496398702264 orig 0.7262949361465871 orig 0.7263975832611322 orig 0.7268964247778058 orig 0.7285707523114979 orig 0.7301340880803764 orig 0.7269740668125451 cifn 0.7278188159689307 cifn 0.7275086198933423 cifn 0.7276351940818131 cifn 0.7273577488958836 cifn 0.7277690819464624 cifn 0.7278458229266107 cifn 0.7296295361593366 cifn 0.728026581928134 cifn 0.7279369789175689 cifn 0.7276105280034244 ----------------------------------------------------------- vm1_yield def m i = 0 while i<30_000_000 # while loop 1 i += 1 yield end end m{} orig 1.153991550207138 orig 1.1552532706409693 orig 1.2647252841852605 orig 1.4128894098103046 orig 1.1594278179109097 orig 1.153918731957674 orig 1.1796158030629158 orig 1.1910584531724453 orig 1.1626806417480111 orig 1.1626083170995116 cifn 1.1643764120526612 cifn 1.1830416391603649 cifn 1.1487040757201612 cifn 1.2241750340908766 cifn 1.5848954068496823 cifn 1.1443874761462212 cifn 1.1650265827775002 cifn 1.3986774450168014 cifn 1.1710257092490792 cifn 1.2713724398054183 ----------------------------------------------------------- vm2_array i = 0 while i<6_000_000 # benchmark loop 2 i += 1 a = [1,2,3,4,5,6,7,8,9,10] end orig 0.6857088678516448 orig 0.6808148985728621 orig 0.6863766489550471 orig 0.6800540089607239 orig 0.686523977201432 orig 0.6873296927660704 orig 0.7184590972028673 orig 0.7136592157185078 orig 0.6816064626909792 orig 0.6819374454207718 cifn 0.686010068282485 cifn 0.7043567709624767 cifn 0.7357907160185277 cifn 0.7040512608364224 cifn 0.6846491573378444 cifn 0.6800755090080202 cifn 0.6824314682744443 cifn 0.6774583761580288 cifn 0.726497326977551 cifn 0.6825455809012055 ----------------------------------------------------------- vm2_bigarray i = 0 while i<6_000_000 # benchmark loop 2 i += 1 a = [ 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, ] end orig 6.157837050035596 orig 5.862053561024368 orig 5.86074277292937 orig 5.851383870933205 orig 5.84222208801657 orig 5.848551754839718 orig 5.920058916322887 orig 6.046175413765013 orig 5.993187160231173 orig 6.091680091340095 cifn 6.213847721926868 cifn 6.137450635433197 cifn 6.1732976557686925 cifn 5.989874362945557 cifn 6.076186246238649 cifn 5.917116840835661 cifn 5.921226790640503 cifn 5.912618996575475 cifn 5.861156737897545 cifn 5.830701798666269 ----------------------------------------------------------- vm2_bighash i = 0 while i<60_000 # benchmark loop 2 i += 1 a = {0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 19=>19, 20=>20, 21=>21, 22=>22, 23=>23, 24=>24, 25=>25, 26=>26, 27=>27, 28=>28, 29=>29, 30=>30, 31=>31, 32=>32, 33=>33, 34=>34, 35=>35, 36=>36, 37=>37, 38=>38, 39=>39, 40=>40, 41=>41, 42=>42, 43=>43, 44=>44, 45=>45, 46=>46, 47=>47, 48=>48, 49=>49, 50=>50, 51=>51, 52=>52, 53=>53, 54=>54, 55=>55, 56=>56, 57=>57, 58=>58, 59=>59, 60=>60, 61=>61, 62=>62, 63=>63, 64=>64, 65=>65, 66=>66, 67=>67, 68=>68, 69=>69, 70=>70, 71=>71, 72=>72, 73=>73, 74=>74, 75=>75, 76=>76, 77=>77, 78=>78, 79=>79, 80=>80, 81=>81, 82=>82, 83=>83, 84=>84, 85=>85, 86=>86, 87=>87, 88=>88, 89=>89, 90=>90, 91=>91, 92=>92, 93=>93, 94=>94, 95=>95, 96=>96, 97=>97, 98=>98, 99=>99, 100=>100, 101=>101, 102=>102, 103=>103, 104=>104, 105=>105, 106=>106, 107=>107, 108=>108, 109=>109, 110=>110, 111=>111, 112=>112, 113=>113, 114=>114, 115=>115, 116=>116, 117=>117, 118=>118, 119=>119, 120=>120, 121=>121, 122=>122, 123=>123, 124=>124, 125=>125, 126=>126, 127=>127, 128=>128, 129=>129, 130=>130, 131=>131, 132=>132, 133=>133, 134=>134, 135=>135, 136=>136, 137=>137, 138=>138, 139=>139, 140=>140, 141=>141, 142=>142, 143=>143, 144=>144, 145=>145, 146=>146, 147=>147, 148=>148, 149=>149, 150=>150, 151=>151, 152=>152, 153=>153, 154=>154, 155=>155, 156=>156, 157=>157, 158=>158, 159=>159, 160=>160, 161=>161, 162=>162, 163=>163, 164=>164, 165=>165, 166=>166, 167=>167, 168=>168, 169=>169, 170=>170, 171=>171, 172=>172, 173=>173, 174=>174, 175=>175, 176=>176, 177=>177, 178=>178, 179=>179, 180=>180, 181=>181, 182=>182, 183=>183, 184=>184, 185=>185, 186=>186, 187=>187, 188=>188, 189=>189, 190=>190, 191=>191, 192=>192, 193=>193, 194=>194, 195=>195, 196=>196, 197=>197, 198=>198, 199=>199, 200=>200, 201=>201, 202=>202, 203=>203, 204=>204, 205=>205, 206=>206, 207=>207, 208=>208, 209=>209, 210=>210, 211=>211, 212=>212, 213=>213, 214=>214, 215=>215, 216=>216, 217=>217, 218=>218, 219=>219, 220=>220, 221=>221, 222=>222, 223=>223, 224=>224, 225=>225, 226=>226, 227=>227, 228=>228, 229=>229, 230=>230, 231=>231, 232=>232, 233=>233, 234=>234, 235=>235, 236=>236, 237=>237, 238=>238, 239=>239, 240=>240, 241=>241, 242=>242, 243=>243, 244=>244, 245=>245, 246=>246, 247=>247, 248=>248, 249=>249, 250=>250, 251=>251, 252=>252, 253=>253, 254=>254, 255=>255, 256=>256, 257=>257, 258=>258, 259=>259, 260=>260, 261=>261, 262=>262, 263=>263, 264=>264, 265=>265, 266=>266, 267=>267, 268=>268, 269=>269, 270=>270, 271=>271, 272=>272, 273=>273, 274=>274, 275=>275, 276=>276, 277=>277, 278=>278, 279=>279, 280=>280, 281=>281, 282=>282, 283=>283, 284=>284, 285=>285, 286=>286, 287=>287, 288=>288, 289=>289, 290=>290, 291=>291, 292=>292, 293=>293, 294=>294, 295=>295, 296=>296, 297=>297, 298=>298, 299=>299, 300=>300, 301=>301, 302=>302, 303=>303, 304=>304, 305=>305, 306=>306, 307=>307, 308=>308, 309=>309, 310=>310, 311=>311, 312=>312, 313=>313, 314=>314, 315=>315, 316=>316, 317=>317, 318=>318, 319=>319, 320=>320, 321=>321, 322=>322, 323=>323, 324=>324, 325=>325, 326=>326, 327=>327, 328=>328, 329=>329, 330=>330, 331=>331, 332=>332, 333=>333, 334=>334, 335=>335, 336=>336, 337=>337, 338=>338, 339=>339, 340=>340, 341=>341, 342=>342, 343=>343, 344=>344, 345=>345, 346=>346, 347=>347, 348=>348, 349=>349, 350=>350, 351=>351, 352=>352, 353=>353, 354=>354, 355=>355, 356=>356, 357=>357, 358=>358, 359=>359, 360=>360, 361=>361, 362=>362, 363=>363, 364=>364, 365=>365, 366=>366, 367=>367, 368=>368, 369=>369, 370=>370, 371=>371, 372=>372, 373=>373, 374=>374, 375=>375, 376=>376, 377=>377, 378=>378, 379=>379, 380=>380, 381=>381, 382=>382, 383=>383, 384=>384, 385=>385, 386=>386, 387=>387, 388=>388, 389=>389, 390=>390, 391=>391, 392=>392, 393=>393, 394=>394, 395=>395, 396=>396, 397=>397, 398=>398, 399=>399, 400=>400, 401=>401, 402=>402, 403=>403, 404=>404, 405=>405, 406=>406, 407=>407, 408=>408, 409=>409, 410=>410, 411=>411, 412=>412, 413=>413, 414=>414, 415=>415, 416=>416, 417=>417, 418=>418, 419=>419, 420=>420, 421=>421, 422=>422, 423=>423, 424=>424, 425=>425, 426=>426, 427=>427, 428=>428, 429=>429, 430=>430, 431=>431, 432=>432, 433=>433, 434=>434, 435=>435, 436=>436, 437=>437, 438=>438, 439=>439, 440=>440, 441=>441, 442=>442, 443=>443, 444=>444, 445=>445, 446=>446, 447=>447, 448=>448, 449=>449, 450=>450, 451=>451, 452=>452, 453=>453, 454=>454, 455=>455, 456=>456, 457=>457, 458=>458, 459=>459, 460=>460, 461=>461, 462=>462, 463=>463, 464=>464, 465=>465, 466=>466, 467=>467, 468=>468, 469=>469, 470=>470, 471=>471, 472=>472, 473=>473, 474=>474, 475=>475, 476=>476, 477=>477, 478=>478, 479=>479, 480=>480, 481=>481, 482=>482, 483=>483, 484=>484, 485=>485, 486=>486, 487=>487, 488=>488, 489=>489, 490=>490, 491=>491, 492=>492, 493=>493, 494=>494, 495=>495, 496=>496, 497=>497, 498=>498, 499=>499, 500=>500,} end orig 2.8244022610597312 orig 2.9154586638323963 orig 2.874817206989974 orig 2.9084262009710073 orig 2.8846738687716424 orig 2.9102514507248998 orig 2.998303819913417 orig 2.879160991869867 orig 2.9933575447648764 orig 2.887917694170028 cifn 2.9311630339361727 cifn 2.938509806059301 cifn 2.8430450628511608 cifn 3.1845397278666496 cifn 3.0491150207817554 cifn 2.934873305261135 cifn 3.1428922968916595 cifn 3.095313574653119 cifn 2.9304039156995714 cifn 2.921434011310339 ----------------------------------------------------------- vm2_case i = 0 while i<6_000_000 # while loop 2 case :foo when :bar raise when :baz raise when :boo raise when :foo i += 1 end end orig 0.24809721764177084 orig 0.21180836111307144 orig 0.19566424703225493 orig 0.19807590078562498 orig 0.19617359014227986 orig 0.20041503198444843 orig 0.1958283199928701 orig 0.19639681093394756 orig 0.19511761609464884 orig 0.19624130008742213 cifn 0.19581976626068354 cifn 0.1963144582696259 cifn 0.22336497018113732 cifn 0.2210962469689548 cifn 0.22008865606039762 cifn 0.21058663306757808 cifn 0.19633632386103272 cifn 0.1998155489563942 cifn 0.19611713895574212 cifn 0.1961935949511826 ----------------------------------------------------------- vm2_defined_method class Object define_method(:m){} end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m; m; m; m; m; m; m; m; end orig 3.0921339350752532 orig 2.712335143238306 orig 3.1838930719532073 orig 2.723826596979052 orig 3.705374638084322 orig 2.84000396495685 orig 2.7142635006457567 orig 2.709776516072452 orig 2.7192300842143595 orig 2.845750186126679 cifn 2.809581369627267 cifn 2.708717786706984 cifn 2.72545533394441 cifn 2.7915853071026504 cifn 2.7091538002714515 cifn 2.858184075448662 cifn 2.929590791929513 cifn 2.9435881413519382 cifn 2.986514024436474 cifn 2.95235051587224 ----------------------------------------------------------- vm2_dstr i = 0 x = y = 'z' while i<6_000_000 # benchmark loop 2 i += 1 str = "foo#{x}bar#{y}baz" end orig 1.343745713122189 orig 1.2847806299105287 orig 1.2403381718322635 orig 1.242556227836758 orig 1.3371795718558133 orig 1.2406079932115972 orig 1.2741483128629625 orig 1.2417621882632375 orig 1.2395418309606612 orig 1.241292392835021 cifn 1.2359406012110412 cifn 1.2158466908149421 cifn 1.21548291714862 cifn 1.2144829789176583 cifn 1.2167805801145732 cifn 1.2186495610512793 cifn 1.2765466230921447 cifn 1.2307518790476024 cifn 1.2138075442053378 cifn 1.2149398839101195 ----------------------------------------------------------- vm2_eval i = 0 while i<6_000_000 # benchmark loop 2 i += 1 eval("1") end orig 11.842829834204167 orig 11.885431429836899 orig 11.949753688182682 orig 12.004896083846688 orig 11.981422685086727 orig 11.914329102262855 orig 11.94446267420426 orig 12.109607787337154 orig 11.966528754681349 orig 12.438509004190564 cifn 11.76813380420208 cifn 11.91427539801225 cifn 12.079256553668529 cifn 12.051187735050917 cifn 11.815964329056442 cifn 11.896929589100182 cifn 13.47034189896658 cifn 11.90407767193392 cifn 11.951957445126027 cifn 11.737751381006092 ----------------------------------------------------------- vm2_method def m nil end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m; m; m; m; m; m; m; m; end orig 1.3791444478556514 orig 1.3939873571507633 orig 1.4763902518898249 orig 1.3587546846829355 orig 1.3629887746647 orig 1.4764577811583877 orig 1.4896990419365466 orig 1.3557744692079723 orig 1.3582659740932286 orig 1.358048565685749 cifn 1.4382017217576504 cifn 1.3955414667725563 cifn 1.4165979041717947 cifn 1.3662283779121935 cifn 1.4386914391070604 cifn 1.3940193601883948 cifn 1.3620851528830826 cifn 1.368416024837643 cifn 1.3613774999976158 cifn 1.3684887858107686 ----------------------------------------------------------- vm2_method_missing class C def method_missing mid end end obj = C.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; end orig 1.9764919131994247 orig 1.933936511632055 orig 2.0304402369074523 orig 1.9449073150753975 orig 2.0178840328007936 orig 2.008144331164658 orig 2.063132360111922 orig 1.952315591275692 orig 2.0475193299353123 orig 2.4559033373370767 cifn 2.028759414795786 cifn 1.9850533101707697 cifn 2.1645833677612245 cifn 2.0459538782015443 cifn 2.0016570859588683 cifn 1.9998153168708086 cifn 2.043591978959739 cifn 1.9603555919602513 cifn 2.137962654232979 cifn 2.054748446214944 ----------------------------------------------------------- vm2_method_with_block def m nil end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m{}; m{}; m{}; m{}; m{}; m{}; m{}; m{}; end orig 1.6854991307482123 orig 1.5377933061681688 orig 1.5386928468942642 orig 1.550413419958204 orig 1.5230660559609532 orig 1.558642728254199 orig 1.5495765767991543 orig 1.5754026779904962 orig 1.5387899028137326 orig 1.5262272139079869 cifn 1.536930059082806 cifn 1.543233291245997 cifn 1.5510568744502962 cifn 1.5595447393134236 cifn 1.5447717932984233 cifn 1.5414099982008338 cifn 1.5413509500212967 cifn 1.5548722269013524 cifn 1.586198644246906 cifn 1.755708355922252 ----------------------------------------------------------- vm2_mutex require 'thread' m = Mutex.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m.synchronize{} end orig 0.7398307230323553 orig 0.7576706409454346 orig 0.737231879029423 orig 0.817217072006315 orig 0.780409405939281 orig 0.9341518497094512 orig 0.9210059102624655 orig 0.7410158538259566 orig 0.7727235839702189 orig 0.7377248439006507 cifn 0.7416750197298825 cifn 0.7622303739190102 cifn 0.7930958089418709 cifn 0.9451246187090874 cifn 0.7405803138390183 cifn 0.7400859468616545 cifn 0.7422204688191414 cifn 0.7397586959414184 cifn 0.7406866000965238 cifn 0.7404823298566043 ----------------------------------------------------------- vm2_newlambda i = 0 while i<6_000_000 # benchmark loop 2 i += 1 lambda {} end orig 0.7692898451350629 orig 0.7806584220379591 orig 0.7723889811895788 orig 0.7710533561185002 orig 0.776015488896519 orig 0.7724311519414186 orig 0.7825967040844262 orig 0.7750945710577071 orig 0.7912085116840899 orig 0.7869055070914328 cifn 0.7772693699225783 cifn 0.7905570352450013 cifn 0.7758933296427131 cifn 0.7698106779716909 cifn 0.7730894908308983 cifn 0.7733949669636786 cifn 0.7651910791173577 cifn 0.7825705907307565 cifn 0.767451801802963 cifn 0.7964517646469176 ----------------------------------------------------------- vm2_poly_method class C1 def m 1 end end class C2 def m 2 end end o1 = C1.new o2 = C2.new i = 0 while i<6_000_000 # benchmark loop 2 o = (i % 2 == 0) ? o1 : o2 o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i += 1 end orig 2.364573588129133 orig 2.2631437960080802 orig 2.342151415999979 orig 2.252608221024275 orig 2.516042532864958 orig 2.9705494144000113 orig 3.2330155638046563 orig 2.2614151826128364 orig 2.471591825596988 orig 2.9366894187405705 cifn 2.1647653011605144 cifn 2.2153403447009623 cifn 2.214822085108608 cifn 2.1913196621462703 cifn 2.171580976806581 cifn 2.1891771219670773 cifn 2.193935365881771 cifn 2.45366603275761 cifn 2.194987914059311 cifn 2.225169504992664 ----------------------------------------------------------- vm2_poly_method_ov class C1 def m 1 end end class C2 def m 2 end end o1 = C1.new o2 = C2.new i = 0 while i<6_000_000 # benchmark loop 2 o = (i % 2 == 0) ? o1 : o2 # o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i += 1 end orig 0.2725144508294761 orig 0.2728171688504517 orig 0.27310274774208665 orig 0.273298529908061 orig 0.27181289065629244 orig 0.27225185791030526 orig 0.27237560087814927 orig 0.2716346988454461 orig 0.27980647375807166 orig 0.271954583004117 cifn 0.27249310072511435 cifn 0.2731766952201724 cifn 0.27731775492429733 cifn 0.2735112118534744 cifn 0.27453614911064506 cifn 0.27321196999400854 cifn 0.27306319773197174 cifn 0.27153609972447157 cifn 0.27309548389166594 cifn 0.2735607801005244 ----------------------------------------------------------- vm2_proc def m &b b end pr = m{ a = 1 } i = 0 while i<6_000_000 # benchmark loop 2 i += 1 pr.call end orig 0.5242845402099192 orig 0.5065356558188796 orig 0.5281026582233608 orig 0.507437280844897 orig 0.5090924762189388 orig 0.5365097597241402 orig 0.5103032761253417 orig 0.5142256901599467 orig 0.5055836578831077 orig 0.5112542710267007 cifn 0.5307690212503076 cifn 0.520123491063714 cifn 0.5182728408835828 cifn 0.5207995367236435 cifn 0.5076261898502707 cifn 0.5103969862684608 cifn 0.5323573597706854 cifn 0.5088576888665557 cifn 0.5110053052194417 cifn 0.512433857191354 ----------------------------------------------------------- vm2_raise1 def rec n if n > 0 rec n-1 else raise end end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 begin rec 1 rescue # ignore end end orig 5.150614803191274 orig 5.164406104013324 orig 5.134231877047569 orig 5.158559295348823 orig 5.185369651764631 orig 5.140058445744216 orig 5.136819053906947 orig 5.188033944927156 orig 5.167475794907659 orig 5.358237834647298 cifn 5.77413667505607 cifn 5.201006466057152 cifn 5.261153948958963 cifn 5.203997299075127 cifn 5.180085772182792 cifn 5.321039806120098 cifn 5.172751311678439 cifn 5.227551025804132 cifn 5.312888485845178 cifn 5.209367765113711 ----------------------------------------------------------- vm2_raise2 def rec n if n > 0 rec n-1 else raise end end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 begin rec 10 rescue # ignore end end orig 7.959743373095989 orig 8.539769207593054 orig 7.761762740090489 orig 7.736605209764093 orig 7.808368741068989 orig 7.716312938835472 orig 7.787448524031788 orig 8.001577145885676 orig 7.87961008399725 orig 7.70036800717935 cifn 7.822185876779258 cifn 7.998774655163288 cifn 7.7376252971589565 cifn 7.975258027669042 cifn 7.875060483813286 cifn 7.75650967285037 cifn 8.098033735062927 cifn 7.961050508078188 cifn 7.8896797532215714 cifn 7.873247648589313 ----------------------------------------------------------- vm2_regexp i = 0 str = 'xxxhogexxx' while i<6_000_000 # benchmark loop 2 /hoge/ =~ str i += 1 end orig 1.162805185187608 orig 1.3087608399800956 orig 1.1621821159496903 orig 1.160275415983051 orig 1.160969924647361 orig 1.160764204338193 orig 1.2440538881346583 orig 1.1615248005837202 orig 1.1585554019548 orig 1.1607737839221954 cifn 1.1716177314519882 cifn 1.1722683948464692 cifn 1.3540297928266227 cifn 1.175417985767126 cifn 1.1706363689154387 cifn 1.1717564389109612 cifn 1.1723792408593 cifn 1.1722787767648697 cifn 1.1723304893821478 cifn 1.172229928895831 ----------------------------------------------------------- vm2_send class C def m end end o = C.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 o.__send__ :m end orig 0.3746882718987763 orig 0.401164089795202 orig 0.38264396600425243 orig 0.37639385601505637 orig 0.3782128500752151 orig 0.3743576668202877 orig 0.37643988616764545 orig 0.37470172299072146 orig 0.38731420412659645 orig 0.374153520911932 cifn 0.3767481679096818 cifn 0.3783349827863276 cifn 0.3761522169224918 cifn 0.3769687209278345 cifn 0.3801789153367281 cifn 0.37842728616669774 cifn 0.4036256796680391 cifn 0.3808340230025351 cifn 0.38381169410422444 cifn 0.3869627062231302 ----------------------------------------------------------- vm2_super class C def m 1 end end class CC < C def m super() end end obj = CC.new i = 0 while i<6_000_000 # benchmark loop 2 obj.m i += 1 end orig 0.5565563570708036 orig 0.5375671670772135 orig 0.502526125870645 orig 0.6661165752448142 orig 0.59502814989537 orig 0.5208870079368353 orig 0.5446955868974328 orig 0.4962911899201572 orig 0.5185231543146074 orig 0.5111415269784629 cifn 0.5547878751531243 cifn 0.5575772658921778 cifn 0.7291873628273606 cifn 0.5066362121142447 cifn 0.4991877246648073 cifn 0.5344501659274101 cifn 0.5111403451301157 cifn 0.8360882010310888 cifn 0.517064951825887 cifn 0.5474959230050445 ----------------------------------------------------------- vm2_unif1 i = 0 def m a, b end while i<6_000_000 # benchmark loop 2 i += 1 m 100, 200 end orig 0.29789351066574454 orig 0.28584109200164676 orig 0.2723064017482102 orig 0.2722553638741374 orig 0.2997104190289974 orig 0.3893855162896216 orig 0.2812450039200485 orig 0.2715774872340262 orig 0.2714026630856097 orig 0.2713953689672053 cifn 0.2717051850631833 cifn 0.2808708078227937 cifn 0.27162779308855534 cifn 0.30216483399271965 cifn 0.2869124822318554 cifn 0.2815335737541318 cifn 0.2716188058257103 cifn 0.2876148447394371 cifn 0.2722315830178559 cifn 0.2863332210108638 ----------------------------------------------------------- vm2_zsuper i = 0 class C def m a 1 end end class CC < C def m a super end end obj = CC.new while i<6_000_000 # benchmark loop 2 obj.m 10 i += 1 end orig 0.5105559476651251 orig 0.5130281769670546 orig 0.5111110731959343 orig 0.5436687339097261 orig 0.5320061189122498 orig 0.6097249700687826 orig 0.5595755521208048 orig 0.5339053571224213 orig 0.5127865727990866 orig 0.5337075460702181 cifn 0.5192865850403905 cifn 0.5322460308670998 cifn 0.5300412001088262 cifn 0.5160890752449632 cifn 0.5156844658777118 cifn 0.5168309332802892 cifn 0.521081191021949 cifn 0.5158168091438711 cifn 0.5153780081309378 cifn 0.5281254160217941 ----------------------------------------------------------- vm3_backtrace # get last backtrace begin caller(0, 0) rescue ArgumentError alias caller_orig caller def caller lev, n caller_orig(lev)[0..n] end end def rec n if n < 0 100_000.times{ caller(0, 1) } else rec(n-1) end end rec 50 orig 0.12274136720225215 orig 0.1222280696965754 orig 0.12212115107104182 orig 0.12241316307336092 orig 0.12220879178494215 orig 0.12263319827616215 orig 0.12293639034032822 orig 0.12247639894485474 orig 0.12200802098959684 orig 0.1225059600546956 cifn 0.12370949890464544 cifn 0.12434678198769689 cifn 0.12397761270403862 cifn 0.12507308600470424 cifn 0.12356718210503459 cifn 0.1241840529255569 cifn 0.12379983998835087 cifn 0.12426915112882853 cifn 0.1241647182032466 cifn 0.12412418192252517 ----------------------------------------------------------- vm3_clearmethodcache i = 0 while i<200_000 i += 1 Class.new{ def m; end } end orig 0.3347742869518697 orig 0.3340539583005011 orig 0.33636874379590154 orig 0.3344243480823934 orig 0.3351423488929868 orig 0.332209515850991 orig 0.33596015302464366 orig 0.3321249638684094 orig 0.3332154550589621 orig 0.3366783121600747 cifn 0.33558342792093754 cifn 0.33160053100436926 cifn 0.33169161062687635 cifn 0.33045140421018004 cifn 0.33252717927098274 cifn 0.3347252649255097 cifn 0.3341053738258779 cifn 0.33159331511706114 cifn 0.3321106629446149 cifn 0.33527565374970436 ----------------------------------------------------------- vm3_gc #! /usr/bin/ruby 5000.times do 100.times do {"xxxx"=>"yyyy"} end GC.start end orig 2.23378107463941 orig 2.1097091492265463 orig 2.1410200530663133 orig 2.1124107358045876 orig 2.1971998647786677 orig 2.3155393810011446 orig 2.304334122687578 orig 2.135979025159031 orig 2.2425050833262503 orig 2.1757962252013385 cifn 2.157022493891418 cifn 2.1608280721120536 cifn 2.1615994730964303 cifn 2.146670071873814 cifn 3.0396404499188066 cifn 2.1533037652261555 cifn 2.148613156285137 cifn 2.15320680802688 cifn 2.147794372867793 cifn 2.1596630848944187 ----------------------------------------------------------- vm_thread_alive_check1 5_000.times{ t = Thread.new{} while t.alive? Thread.pass end } orig 0.10341933323070407 orig 0.10406159795820713 orig 0.1036485699005425 orig 0.10463611921295524 orig 0.10379328578710556 orig 0.10294350469484925 orig 0.10477276891469955 orig 0.10407248418778181 orig 0.10100423311814666 orig 0.10205481108278036 cifn 0.10160934319719672 cifn 0.1043029110878706 cifn 0.10010028816759586 cifn 0.10161278396844864 cifn 0.10361905116587877 cifn 0.0971845998428762 cifn 0.10291275708004832 cifn 0.10085961315780878 cifn 0.09867118205875158 cifn 0.10258793085813522 ----------------------------------------------------------- vm_thread_close 1000.times { Thread.new { sleep } } i = 0 while i<100_000 # benchmark loop 3 i += 1 IO.pipe.each(&:close) end orig 2.920911348890513 orig 2.993483868893236 orig 3.1326657319441438 orig 3.1405383199453354 orig 2.5623662769794464 orig 3.05048821400851 orig 2.955652718897909 orig 2.6031257710419595 orig 3.145245066843927 orig 2.975940986070782 cifn 2.5617101839743555 cifn 3.078550121281296 cifn 2.59006314817816 cifn 3.0601192573085427 cifn 3.109877451788634 cifn 2.943194170948118 cifn 2.9267335240729153 cifn 3.2619719658978283 cifn 2.661901483312249 cifn 3.039387358818203 ----------------------------------------------------------- vm_thread_create_join i = 0 while i<100_000 # benchmark loop 3 i += 1 Thread.new{ }.join end orig 1.1297991499304771 orig 1.0989042608998716 orig 1.1510657910257578 orig 1.143817171920091 orig 1.1672891220077872 orig 1.1381663233041763 orig 1.166306713130325 orig 1.152822711970657 orig 1.143584999255836 orig 1.1556369261816144 cifn 1.1181843099184334 cifn 1.1659538028761744 cifn 1.1381126050837338 cifn 1.1323504587635398 cifn 1.1267595971003175 cifn 1.1248447434045374 cifn 1.1309492383152246 cifn 1.1427586455829442 cifn 1.1186688248999417 cifn 1.1941332640126348 ----------------------------------------------------------- vm_thread_mutex1 # one thread, one mutex (no contention) require 'thread' m = Mutex.new r = 0 max = 2000 lmax = max * max (1..1).map{ Thread.new{ i = 0 while i