From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A2D681F7C2; Mon, 22 Sep 2014 18:46:45 +0000 (UTC) Date: Mon, 22 Sep 2014 18:46:45 +0000 From: Eric Wong To: spew@80x24.org Subject: benchmarks on Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz Message-ID: References: <1411411308-24223-1-git-send-email-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <1411411308-24223-1-git-send-email-e@80x24.org> List-Id: 2014-09-22 05:38:59 +0000 target 0: orig (ruby 2.2.0dev (2014-09-22 trunk 47681) [x86_64-linux]) at "= b/ruby.orig" target 1: stll (ruby 2.2.0dev (2014-09-22 trunk 47681) [x86_64-linux]) at "= b/ruby" ----------------------------------------------------------- app_answer def ack(m, n) if m =3D=3D 0 then n + 1 elsif n =3D=3D 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 =3D the_answer_to_life_the_universe_and_everything orig 0.053822168 orig 0.054029033 orig 0.05420699 orig 0.05374481 orig 0.054266707 orig 0.053863589 orig 0.057185724 orig 0.05387 orig 0.053834501 orig 0.05408797 stll 0.054842263 stll 0.05406647 stll 0.054126083 stll 0.054508985 stll 0.055946202 stll 0.053851443 stll 0.054151559 stll 0.054021872 stll 0.054684883 stll 0.053992802 ----------------------------------------------------------- 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 =3D 256 IMAGE_HEIGHT =3D 256 NSUBSAMPLES =3D 2 NAO_SAMPLES =3D 8 class Vec def initialize(x, y, z) @x =3D x @y =3D y @z =3D 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 =3D vlength v =3D Vec.new(@x, @y, @z) if len > 1.0e-17 then v.x =3D v.x / len v.y =3D v.y / len v.z =3D v.z / len end v end end class Sphere def initialize(center, radius) @center =3D center @radius =3D radius end attr_reader :center, :radius def intersect(ray, isect) rs =3D ray.org.vsub(@center) b =3D rs.vdot(ray.dir) c =3D rs.vdot(rs) - (@radius * @radius) d =3D b * b - c if d > 0.0 then t =3D - b - Math.sqrt(d) if t > 0.0 and t < isect.t then isect.t =3D t isect.hit =3D true isect.pl =3D Vec.new(ray.org.x + ray.dir.x * t, ray.org.y + ray.dir.y * t, ray.org.z + ray.dir.z * t) n =3D isect.pl.vsub(@center) isect.n =3D n.vnormalize else 0.0 end end nil end end class Plane def initialize(p, n) @p =3D p @n =3D n end def intersect(ray, isect) d =3D -@p.vdot(@n) v =3D ray.dir.vdot(@n) v0 =3D v if v < 0.0 then v0 =3D -v end if v0 < 1.0e-17 then return end t =3D -(ray.org.vdot(@n) + d) / v if t > 0.0 and t < isect.t then isect.hit =3D true isect.t =3D t isect.n =3D @n isect.pl =3D 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 =3D org @dir =3D dir end attr_accessor :org, :dir end class Isect def initialize @t =3D 10000000.0 @hit =3D false @pl =3D Vec.new(0.0, 0.0, 0.0) @n =3D Vec.new(0.0, 0.0, 0.0) end attr_accessor :t, :hit, :pl, :n end def clamp(f) i =3D f * 255.5 if i > 255.0 then i =3D 255.0 end if i < 0.0 then i =3D 0.0 end i.to_i end def otherBasis(basis, n) basis[2] =3D Vec.new(n.x, n.y, n.z) basis[1] =3D Vec.new(0.0, 0.0, 0.0) if n.x < 0.6 and n.x > -0.6 then basis[1].x =3D 1.0 elsif n.y < 0.6 and n.y > -0.6 then basis[1].y =3D 1.0 elsif n.z < 0.6 and n.z > -0.6 then basis[1].z =3D 1.0 else basis[1].x =3D 1.0 end basis[0] =3D basis[1].vcross(basis[2]) basis[0] =3D basis[0].vnormalize basis[1] =3D basis[2].vcross(basis[0]) basis[1] =3D basis[1].vnormalize end class Scene def initialize @spheres =3D Array.new @spheres[0] =3D Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5) @spheres[1] =3D Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5) @spheres[2] =3D Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5) @plane =3D Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0)) end def ambient_occlusion(isect) basis =3D Array.new otherBasis(basis, isect.n) ntheta =3D NAO_SAMPLES nphi =3D NAO_SAMPLES eps =3D 0.0001 occlusion =3D 0.0 p0 =3D 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 =3D rand phi =3D 2.0 * 3.14159265 * rand x =3D Math.cos(phi) * Math.sqrt(1.0 - r) y =3D Math.sin(phi) * Math.sqrt(1.0 - r) z =3D Math.sqrt(r) rx =3D x * basis[0].x + y * basis[1].x + z * basis[2].x ry =3D x * basis[0].y + y * basis[1].y + z * basis[2].y rz =3D x * basis[0].z + y * basis[1].z + z * basis[2].z raydir =3D Vec.new(rx, ry, rz) ray =3D Ray.new(p0, raydir) occisect =3D 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 =3D occlusion + 1.0 else 0.0 end end end occlusion =3D (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * np= hi.to_f) Vec.new(occlusion, occlusion, occlusion) end def render(w, h, nsubsamples) cnt =3D 0 nsf =3D nsubsamples.to_f h.times do |y| w.times do |x| rad =3D Vec.new(0.0, 0.0, 0.0) # Subsmpling nsubsamples.times do |v| nsubsamples.times do |u| cnt =3D cnt + 1 wf =3D w.to_f hf =3D h.to_f xf =3D x.to_f yf =3D y.to_f uf =3D u.to_f vf =3D v.to_f px =3D (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0) py =3D -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0) eye =3D Vec.new(px, py, -1.0).vnormalize ray =3D Ray.new(Vec.new(0.0, 0.0, 0.0), eye) isect =3D 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 =3D ambient_occlusion(isect) rad.x =3D rad.x + col.x rad.y =3D rad.y + col.y rad.z =3D rad.z + col.z end end end r =3D rad.x / (nsf * nsf) g =3D rad.y / (nsf * nsf) b =3D 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 43.076738901 orig 43.028016045 orig 43.197667739 orig 44.312146415 orig 42.993375293 orig 43.096511663 orig 43.111997889 orig 43.14533459 orig 42.96419694 orig 43.581617607 stll 42.731068343 stll 42.91853553 stll 43.539508991 stll 46.036135327 stll 44.702937628 stll 43.279324603 stll 43.322062172 stll 46.042519525 stll 43.711278628 stll 44.468188102 ----------------------------------------------------------- app_erb # # Create many HTML strings with ERB. # require 'erb' data =3D DATA.read max =3D 15_000 title =3D "hello world!" content =3D "hello world!\n" * 10 max.times{ ERB.new(data).result(binding) } __END__ <%=3D title %>

<%=3D title %>

<%=3D content %>

orig 0.877973788 orig 0.873433795 orig 0.937733265 orig 0.884718992 orig 0.87286147 orig 0.890507022 orig 0.873429153 orig 0.870941343 orig 0.874882247 orig 0.87176688 stll 0.872209629 stll 0.868533232 stll 0.872928831 stll 0.873147049 stll 0.867231466 stll 0.872875146 stll 0.874811633 stll 0.882248124 stll 0.873005187 stll 0.891447572 ----------------------------------------------------------- app_factorial def fact(n) if(n > 1) n * fact(n-1) else 1 end end 100.times { fact(5000) } orig 0.805401632 orig 0.806380912 orig 0.805792719 orig 0.806436317 orig 0.808000536 orig 0.804695953 orig 0.804775601 orig 0.808004935 orig 0.808079104 orig 0.806497236 stll 0.752931959 stll 0.75402637 stll 0.752723328 stll 0.75777318 stll 0.752127311 stll 0.752263454 stll 0.755094515 stll 0.754753176 stll 0.753876487 stll 0.757509723 ----------------------------------------------------------- app_fib def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(34) orig 0.477865003 orig 0.499373551 orig 0.479733716 orig 0.480720254 orig 0.4740355 orig 0.480593195 orig 0.475646497 orig 0.481992312 orig 0.475438603 orig 0.591133305 stll 0.476690551 stll 0.479981071 stll 0.488814861 stll 0.506066234 stll 0.476148832 stll 0.477693471 stll 0.480147474 stll 0.475824736 stll 0.623956849 stll 0.502471049 ----------------------------------------------------------- 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 =3D -> 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 =3D -> l { LEFT[RIGHT[l]] } IF =3D -> b { b } LEFT =3D -> p { p[-> x { -> y { x } } ] } RIGHT =3D -> p { p[-> x { -> y { y } } ] } IS_EMPTY =3D LEFT REST =3D -> 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 =3D [] until to_boolean(IS_EMPTY[proc]) array.push(FIRST[proc]) proc =3D 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 =3D to_array(solution).map do |p| to_string(p) end answer_ary =3D answer.to_a # puts answer_ary orig 68.4564067 orig 69.127990261 orig 70.253889911 orig 67.784253118 orig 67.891071347 orig 66.856999744 orig 68.239627371 orig 68.355507495 orig 65.787745599 orig 66.527444796 stll 69.579906637 stll 67.215046349 stll 66.969033824 stll 65.271179722 stll 65.783239733 stll 69.280211269 stll 66.660859374 stll 66.130403877 stll 64.967371958 stll 63.875867786 ----------------------------------------------------------- app_mandelbrot require 'complex' def mandelbrot? z i =3D 0 while i<100 i +=3D 1 z =3D z * z return false if z.abs > 2 end true end ary =3D [] (0..1000).each{|dx| (0..1000).each{|dy| x =3D dx / 50.0 y =3D dy / 50.0 c =3D Complex(x, y) ary << c if mandelbrot?(c) } } orig 1.459894239 orig 1.489491642 orig 0.902506879 orig 0.903327177 orig 0.898419648 orig 0.899715521 orig 0.898631131 orig 0.900987302 orig 0.901816105 orig 0.907537929 stll 0.89145598 stll 0.890685262 stll 0.906450235 stll 0.896532126 stll 0.892681072 stll 0.890940665 stll 0.899069383 stll 1.08214218 stll 0.910197243 stll 0.89143809 ----------------------------------------------------------- app_pentomino #!/usr/local/bin/ruby # This program is contributed by Shin Nishiyama # modified by K.Sasada NP =3D 5 ROW =3D 8 + NP COL =3D 8 $p =3D [] $b =3D [] $no =3D 0 def piece(n, a, nb) nb.each{|x| a[n] =3D x if n =3D=3D NP-1 $p << [a.sort] else nbc=3Dnb.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 =3D a[0] a[1] =3D ud(a0) a[2] =3D rl(a0) a[3] =3D ud(rl(a0)) a[4] =3D xy(a0) a[5] =3D ud(xy(a0)) a[6] =3D rl(xy(a0)) a[7] =3D ud(rl(xy(a0))) a.sort! a.uniq! end $p.uniq!.sort! {|x,y| x[0] <=3D> y[0] } end def mkboard (0...ROW*COL).each{|i| if i % ROW >=3D ROW-NP $b[i] =3D -2 else $b[i] =3D -1 end $b[3*ROW+3]=3D$b[3*ROW+4]=3D$b[4*ROW+3]=3D$b[4*ROW+4]=3D-2 } end def pboard return # skip print print "No. #$no\n" (0...COL).each{|i| print "|" (0...ROW-NP).each{|j| x =3D $b[i*ROW+j] if x < 0 print "..|" else printf "%2d|",x+1 end } print "\n" } print "\n" end $pnum=3D[] def setpiece(a,pos) if a.length =3D=3D $p.length then $no +=3D 1 pboard return end while $b[pos] !=3D -1 pos +=3D 1 end ($pnum - a).each do |i| $p[i].each do |x| f =3D 0 x.each{|s| if $b[pos+s] !=3D -1 f=3D1 break end } if f =3D=3D 0 then x.each{|s| $b[pos+s] =3D i } a << i setpiece(a.dup, pos) a.pop x.each{|s| $b[pos+s] =3D -1 } end end end end mkpieces mkboard $p[4] =3D [$p[4][0]] $pnum =3D (0...$p.length).to_a setpiece([],0) __END__ # original NP =3D 5 ROW =3D 8 + NP COL =3D 8 $p =3D [] $b =3D [] $no =3D 0 def piece(n,a,nb) for x in nb a[n] =3D x if n =3D=3D NP-1 $p << [a.sort] else nbc=3Dnb.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 =3D a[0] a[1] =3D ud(a0) a[2] =3D rl(a0) a[3] =3D ud(rl(a0)) a[4] =3D xy(a0) a[5] =3D ud(xy(a0)) a[6] =3D rl(xy(a0)) a[7] =3D ud(rl(xy(a0))) a.sort! a.uniq! end $p.uniq!.sort! {|x,y| x[0] <=3D> y[0] } end def mkboard for i in 0...ROW*COL if i % ROW >=3D ROW-NP $b[i] =3D -2 else $b[i] =3D -1 end $b[3*ROW+3]=3D$b[3*ROW+4]=3D$b[4*ROW+3]=3D$b[4*ROW+4]=3D-2 end end def pboard print "No. #$no\n" for i in 0...COL print "|" for j in 0...ROW-NP x =3D $b[i*ROW+j] if x < 0 print "..|" else printf "%2d|",x+1 end end print "\n" end print "\n" end $pnum=3D[] def setpiece(a,pos) if a.length =3D=3D $p.length then $no +=3D 1 pboard return end while $b[pos] !=3D -1 pos +=3D 1 end ($pnum - a).each do |i| $p[i].each do |x| f =3D 0 for s in x do if $b[pos+s] !=3D -1 f=3D1 break end end if f =3D=3D 0 then for s in x do $b[pos+s] =3D i end a << i setpiece(a.dup, pos) a.pop for s in x do $b[pos+s] =3D -1 end end end end end mkpieces mkboard $p[4] =3D [$p[4][0]] $pnum =3D (0...$p.length).to_a setpiece([],0) orig 13.538910944 orig 13.649177685 orig 13.449619533 orig 13.874335848 orig 13.704765446 orig 13.940837522 orig 14.643880507 orig 13.702187804 orig 13.56631364 orig 13.460903579 stll 13.960857016 stll 14.283383114 stll 13.892281614 stll 13.792446335 stll 13.585338039 stll 14.079598714 stll 13.541945066 stll 13.555718528 stll 13.688990303 stll 13.653538944 ----------------------------------------------------------- app_raise i =3D 0 while i<300000 i +=3D 1 begin raise rescue end end orig 0.256718303 orig 0.256379292 orig 0.260501366 orig 0.256184826 orig 0.256770062 orig 0.259899614 orig 0.25704115 orig 0.255111165 orig 0.263036359 orig 0.254985853 stll 0.255509678 stll 0.256840589 stll 0.261421628 stll 0.258192571 stll 0.25849846 stll 0.258302149 stll 0.255546399 stll 0.261529648 stll 0.259741815 stll 0.255793305 ----------------------------------------------------------- app_strconcat i =3D 0 while i<2_000_000 "#{1+1} #{1+1} #{1+1}" i +=3D 1 end orig 0.960328798 orig 0.977739962 orig 0.968757826 orig 0.966953146 orig 0.955175821 orig 0.968254937 orig 0.966052117 orig 0.957227335 orig 0.968715024 orig 0.955896901 stll 0.936486221 stll 0.932618274 stll 0.93241836 stll 0.958049731 stll 0.930236464 stll 0.93580221 stll 0.927296582 stll 0.930261898 stll 0.949535208 stll 0.997820343 ----------------------------------------------------------- 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.751258597 orig 0.673566743 orig 0.673689533 orig 0.715104175 orig 0.66300676 orig 0.669495475 orig 0.805775253 orig 0.70083882 orig 0.705970981 orig 0.818605321 stll 0.663240028 stll 0.697075786 stll 0.699114141 stll 0.662322789 stll 0.662610921 stll 0.665765452 stll 0.67200912 stll 0.662522779 stll 0.683096156 stll 0.662753224 ----------------------------------------------------------- app_tarai def tarai( x, y, z ) if x <=3D 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.556255576 orig 0.553993818 orig 0.5601169 orig 0.558580523 orig 0.550725365 orig 0.568340898 orig 0.549644452 orig 0.567195744 orig 0.553216743 orig 0.55903324 stll 0.54721175 stll 0.546947964 stll 0.553037629 stll 0.547740836 stll 0.551975179 stll 0.555337569 stll 0.549248576 stll 0.553858963 stll 0.550279761 stll 0.553504042 ----------------------------------------------------------- app_uri require 'uri' 100_000.times{ uri =3D URI.parse('http://www.ruby-lang.org') uri.scheme uri.host uri.port } orig 0.678858713 orig 0.679524437 orig 0.70871908 orig 0.689013331 orig 0.683252542 orig 0.681265405 orig 0.687151738 orig 0.679977733 orig 0.679899615 orig 0.685387708 stll 0.663888328 stll 0.668038202 stll 0.674654907 stll 0.662838139 stll 0.670028513 stll 0.659243954 stll 0.667394447 stll 0.665213561 stll 0.669254498 stll 0.679531385 ----------------------------------------------------------- hash_aref_miss h =3D {} strs =3D ('a'..'z').to_a.map!(&:freeze) strs.each { |s| h[s] =3D s } strs =3D ('A'..'Z').to_a 200_000.times { strs.each { |s| h[s] } } orig 0.446768558 orig 0.441774664 orig 0.440020956 orig 0.419697422 orig 0.42437844 orig 0.435643711 orig 0.437852003 orig 0.436893765 orig 0.422652494 orig 0.418014289 stll 0.445995292 stll 0.449304373 stll 0.433700582 stll 0.474588809 stll 0.49473485 stll 0.46307417 stll 0.443920226 stll 0.45626427 stll 0.436658571 stll 0.450609853 ----------------------------------------------------------- hash_aref_str h =3D {} strs =3D ('a'..'z').to_a.map!(&:freeze) strs.each { |s| h[s] =3D s } 200_000.times { strs.each { |s| h[s] } } orig 0.429413779 orig 0.406133564 orig 0.413652752 orig 0.407510655 orig 0.432466956 orig 0.406426398 orig 0.65012434 orig 0.613034347 orig 0.404176082 orig 0.538524857 stll 0.405808621 stll 0.413312202 stll 0.401850785 stll 0.397737761 stll 0.396488459 stll 0.415100215 stll 0.408193783 stll 0.407542879 stll 0.406234235 stll 0.406430393 ----------------------------------------------------------- hash_aref_sym h =3D {} syms =3D ('a'..'z').to_a.map(&:to_sym) syms.each { |s| h[s] =3D s } 200_000.times { syms.each { |s| h[s] } } orig 0.615211082 orig 0.782243067 orig 0.781443557 orig 0.64885976 orig 0.715190894 orig 0.615359601 orig 0.607669017 orig 0.610745167 orig 0.616113301 orig 0.619308977 stll 0.619563668 stll 0.612723157 stll 0.611511672 stll 0.652681754 stll 0.698859367 stll 0.616637831 stll 0.618543489 stll 0.628100083 stll 0.634441625 stll 0.614356095 ----------------------------------------------------------- hash_aref_sym_long h =3D {} syms =3D %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] =3D s } 200_000.times { syms.each { |s| h[s] } } orig 1.374003318 orig 1.383922357 orig 1.369967781 orig 1.372910504 orig 1.375160122 orig 1.375002345 orig 1.378900439 orig 1.390391656 orig 1.381341628 orig 1.376968608 stll 1.397013071 stll 1.390732093 stll 1.650411114 stll 1.397701355 stll 1.450352241 stll 1.492276221 stll 1.398620443 stll 1.440458357 stll 1.412398528 stll 1.468146035 ----------------------------------------------------------- hash_flatten h =3D {} 10000.times do |i| h[i] =3D nil end 1000.times do h.flatten end orig 0.412321897 orig 0.40762904 orig 0.410505076 orig 0.411412774 orig 0.412726052 orig 0.409271151 orig 0.408371527 orig 0.411232503 orig 0.412040655 orig 0.417467342 stll 0.425944272 stll 0.419393809 stll 0.419178041 stll 0.422701223 stll 0.42640161 stll 0.431700433 stll 0.425823307 stll 0.428960291 stll 0.427122089 stll 0.421448606 ----------------------------------------------------------- hash_ident_num h =3D {}.compare_by_identity nums =3D (1..26).to_a nums.each { |n| h[n] =3D n } 200_000.times { nums.each { |n| h[n] } } orig 0.295713337 orig 0.283685437 orig 0.284802222 orig 0.287065827 orig 0.285974218 orig 0.29045913 orig 0.287852136 orig 0.281939658 orig 0.302169303 orig 0.285425191 stll 0.283365793 stll 0.283044646 stll 0.283608866 stll 0.2947435 stll 0.282815534 stll 0.286135003 stll 0.284034278 stll 0.284348426 stll 0.282969689 stll 0.29209817 ----------------------------------------------------------- hash_ident_obj h =3D {}.compare_by_identity objs =3D 26.times.map { Object.new } objs.each { |o| h[o] =3D o } 200_000.times { objs.each { |o| h[o] } } orig 0.299977594 orig 0.28323321 orig 0.279770218 orig 0.288053726 orig 0.27808 orig 0.302275651 orig 0.282260369 orig 0.289452943 orig 0.290050327 orig 0.286439327 stll 0.281474478 stll 0.45254817 stll 0.284468923 stll 0.291538696 stll 0.307934031 stll 0.27969676 stll 0.282224447 stll 0.299456978 stll 0.288548865 stll 0.295508415 ----------------------------------------------------------- hash_ident_str h =3D {}.compare_by_identity strs =3D ('a'..'z').to_a strs.each { |s| h[s] =3D s } 200_000.times { strs.each { |s| h[s] } } orig 0.281492569 orig 0.279452627 orig 0.306886348 orig 0.293875706 orig 0.27767955 orig 0.282340644 orig 0.282513711 orig 0.277737484 orig 0.27840241 orig 0.306377801 stll 0.285180983 stll 0.286158359 stll 0.28488322 stll 0.2789034 stll 0.282665979 stll 0.310667206 stll 0.304831145 stll 0.304359489 stll 0.308089904 stll 0.304928809 ----------------------------------------------------------- hash_ident_sym h =3D {}.compare_by_identity syms =3D ('a'..'z').to_a.map(&:to_sym) syms.each { |s| h[s] =3D s } 200_000.times { syms.each { |s| h[s] } } orig 0.305813012 orig 0.303189703 orig 0.301997459 orig 0.300660626 orig 0.300163474 orig 0.301810958 orig 0.298706863 orig 0.311960511 orig 0.320109957 orig 0.302986946 stll 0.32614618 stll 0.304887916 stll 0.315441648 stll 0.326258758 stll 0.324392301 stll 0.32748039 stll 0.325020528 stll 0.301887967 stll 0.302193528 stll 0.322104392 ----------------------------------------------------------- hash_keys h =3D {} 10000.times do |i| h[i] =3D nil end 5000.times do h.keys end orig 0.237521622 orig 0.23922897 orig 0.238281437 orig 0.238138736 orig 0.237818849 orig 0.2378655 orig 0.237608242 orig 0.238036116 orig 0.236039937 orig 0.235813287 stll 0.263477427 stll 0.258049086 stll 0.262820406 stll 0.258006327 stll 0.260327548 stll 0.258086656 stll 0.258101371 stll 0.261393187 stll 0.263826948 stll 0.263821759 ----------------------------------------------------------- hash_shift h =3D {} 10000.times do |i| h[i] =3D nil end 50000.times do k, v =3D h.shift h[k] =3D v end orig 0.037325564 orig 0.037761812 orig 0.037403326 orig 0.036865859 orig 0.037000981 orig 0.037950627 orig 0.037680922 orig 0.037717904 orig 0.037626562 orig 0.036707708 stll 0.03798574 stll 0.037781371 stll 0.037426497 stll 0.037792447 stll 0.037706575 stll 0.037963926 stll 0.036547303 stll 0.037862104 stll 0.037668743 stll 0.037850759 ----------------------------------------------------------- hash_values h =3D {} 10000.times do |i| h[i] =3D nil end 5000.times do h.values end orig 0.248007122 orig 0.249332361 orig 0.249889164 orig 0.249408139 orig 0.249554509 orig 0.24780729 orig 0.248163849 orig 0.249284379 orig 0.255694909 orig 0.249493122 stll 0.255092865 stll 0.255601239 stll 0.258623913 stll 0.255917981 stll 0.254690221 stll 0.255258993 stll 0.259686026 stll 0.258781678 stll 0.25826431 stll 0.259851974 ----------------------------------------------------------- io_file_create # # Create files # max =3D 200_000 file =3D './tmpfile_of_bm_io_file_create' max.times{ f =3D open(file, 'w') f.close#(true) } File.unlink(file) orig 1.149395899 orig 1.111947451 orig 1.148424115 orig 1.123299421 orig 1.078547687 orig 1.098754876 orig 1.094469825 orig 1.115538889 orig 1.087441845 orig 1.093890361 stll 1.122687358 stll 1.134292887 stll 1.1001334 stll 1.10556303 stll 1.109311338 stll 1.117908214 stll 1.145130799 stll 1.112610468 stll 1.113446261 stll 1.104785981 ----------------------------------------------------------- io_file_read # # Seek and Read file. # require 'tempfile' max =3D 200_000 str =3D "Hello world! " * 1000 f =3D Tempfile.new('yarv-benchmark') f.write str max.times{ f.seek 0 f.read } orig 1.125019709 orig 1.13541136 orig 1.137872765 orig 1.134047156 orig 1.144845212 orig 1.129636485 orig 1.115561785 orig 1.137242899 orig 1.139068138 orig 1.162766904 stll 1.15143518 stll 1.127682375 stll 1.154615488 stll 1.116836046 stll 1.11798176 stll 1.151602558 stll 1.124061101 stll 1.144359065 stll 1.126918446 stll 1.180646534 ----------------------------------------------------------- io_file_write # # Seek and Write file. # require 'tempfile' max =3D 200_000 str =3D "Hello world! " * 1000 f =3D Tempfile.new('yarv-benchmark') max.times{ f.seek 0 f.write str } orig 0.776067606 orig 0.797726835 orig 0.778702876 orig 0.787620677 orig 0.77398871 orig 0.776857011 orig 0.781660664 orig 0.801027151 orig 0.784763445 orig 0.784689316 stll 0.811236564 stll 0.880919813 stll 0.856910608 stll 0.803084827 stll 0.781769853 stll 0.780891689 stll 0.781802785 stll 0.786309619 stll 0.780036884 stll 0.809695371 ----------------------------------------------------------- io_select # IO.select performance w =3D [ IO.pipe[1] ]; nr =3D 1000000 nr.times { IO.select nil, w } orig 1.44421145 orig 1.500961778 orig 1.340275243 orig 1.333589151 orig 1.343530587 orig 1.388690989 orig 1.330531973 orig 1.352735683 orig 1.331536008 orig 1.334436513 stll 1.326947365 stll 1.321638113 stll 1.40019153 stll 1.464163825 stll 1.35215768 stll 1.331160097 stll 1.325573937 stll 1.32871885 stll 1.394282438 stll 1.326135512 ----------------------------------------------------------- io_select2 # IO.select performance. worst case of single fd. ios =3D [] nr =3D 1000000 if defined?(Process::RLIMIT_NOFILE) max =3D Process.getrlimit(Process::RLIMIT_NOFILE)[0] else max =3D 64 end puts "max fd: #{max} (results not apparent with <=3D 1024 max fd)" ((max / 2) - 10).times do ios.concat IO.pipe end last =3D [ ios[-1] ] puts "last IO: #{last[0].inspect}" nr.times do IO.select nil, last end orig 1.484366617 orig 1.519561653 orig 1.49992768 orig 1.678054688 orig 1.478214104 orig 1.690015728 orig 1.736267968 orig 1.519632113 orig 1.484009967 orig 1.498426631 stll 1.477902349 stll 1.480356925 stll 1.510644959 stll 1.488792033 stll 1.491730639 stll 1.484534491 stll 1.474508188 stll 1.488224728 stll 1.479929293 stll 1.484428486 ----------------------------------------------------------- io_select3 # IO.select performance. a lot of fd ios =3D [] nr =3D 100 if defined?(Process::RLIMIT_NOFILE) max =3D Process.getrlimit(Process::RLIMIT_NOFILE)[0] else max =3D 64 end puts "max fd: #{max} (results not apparent with <=3D 1024 max fd)" (max - 10).times do r, w =3D IO.pipe r.close ios.push w end nr.times do IO.select nil, ios end orig 0.035239068 orig 0.035185953 orig 0.035496549 orig 0.035138319 orig 0.035191802 orig 0.035105515 orig 0.035467736 orig 0.035069739 orig 0.035290586 orig 0.035655578 stll 0.035575096 stll 0.035514868 stll 0.035360184 stll 0.035532505 stll 0.035664328 stll 0.035364631 stll 0.035594935 stll 0.035676978 stll 0.035750193 stll 0.036109592 ----------------------------------------------------------- loop_for for i in 1..30_000_000 # end orig 1.068398738 orig 1.089524688 orig 1.06515046 orig 1.076397493 orig 1.128322392 orig 1.056983289 orig 1.068786863 orig 1.06075239 orig 1.090364107 orig 1.05966495 stll 1.070177283 stll 1.199340781 stll 1.046856599 stll 1.228460821 stll 1.055218017 stll 1.081184898 stll 1.446706991 stll 1.075304924 stll 1.091709721 stll 1.047952522 ----------------------------------------------------------- loop_generator max =3D 600000 if defined? Fiber gen =3D (1..max).each loop do gen.next end else require 'generator' gen =3D Generator.new((0..max)) while gen.next? gen.next end end orig 0.69687891 orig 0.66540424 orig 0.679628263 orig 0.679925684 orig 0.668787193 orig 0.663496081 orig 0.675394757 orig 0.668240526 orig 0.664183383 orig 0.668584543 stll 0.664589303 stll 0.664632547 stll 0.66494632 stll 0.66598414 stll 0.668229128 stll 0.703826444 stll 0.666750904 stll 0.696360115 stll 0.667385923 stll 0.664486322 ----------------------------------------------------------- loop_times 30_000_000.times{|e|} orig 0.980117059 orig 0.99439093 orig 0.979838402 orig 0.980894064 orig 0.976447361 orig 1.017838667 orig 0.982484037 orig 0.975619088 orig 0.994094528 orig 0.975998638 stll 0.980488121 stll 1.012998277 stll 0.994445077 stll 1.021846043 stll 0.995144058 stll 0.980257679 stll 0.980164899 stll 0.982455737 stll 0.980923491 stll 0.995939417 ----------------------------------------------------------- loop_whileloop i =3D 0 while i<30_000_000 # benchmark loop 1 i +=3D 1 end orig 0.519354884 orig 0.51248877 orig 0.528460095 orig 0.572378986 orig 0.522353833 orig 0.512769352 orig 0.51291327 orig 0.513174436 orig 0.512962627 orig 0.512993475 stll 0.512713733 stll 0.513168691 stll 0.513058356 stll 0.526820777 stll 0.597845519 stll 0.598345559 stll 0.513074299 stll 0.512725396 stll 0.512297872 stll 0.512275679 ----------------------------------------------------------- loop_whileloop2 i =3D 0 while i< 6_000_000 # benchmark loop 2 i +=3D 1 end orig 0.119143733 orig 0.119069969 orig 0.118170264 orig 0.119768966 orig 0.119649986 orig 0.119431425 orig 0.119271081 orig 0.117096695 orig 0.122974262 orig 0.119396226 stll 0.119527968 stll 0.119188292 stll 0.119380972 stll 0.119252149 stll 0.119249809 stll 0.119733445 stll 0.119868804 stll 0.119451459 stll 0.119356097 stll 0.11951881 ----------------------------------------------------------- securerandom require "securerandom" 20_0000.times do SecureRandom.random_number(100) end orig 0.648002646 orig 0.616914537 orig 0.643030421 orig 0.642372636 orig 0.626927428 orig 0.625634949 orig 0.626575619 orig 0.638432885 orig 0.635409301 orig 0.672691913 stll 0.621063098 stll 0.664200477 stll 0.628247305 stll 0.620684543 stll 0.623475494 stll 0.623570129 stll 0.621391886 stll 0.62354543 stll 0.615683188 stll 0.639126611 ----------------------------------------------------------- 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 =3D=3D 0 then n + 1 elsif n =3D=3D 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end NUM =3D 9 ack(3, NUM) orig 0.554878476 orig 0.55431934 orig 0.554912154 orig 0.554768344 orig 0.554965378 orig 0.555051582 orig 0.555390224 orig 0.561993 orig 0.554681063 orig 0.554925765 stll 0.555434009 stll 0.5543861 stll 0.555613879 stll 0.562025374 stll 0.567785032 stll 0.555452116 stll 0.554703316 stll 0.554925696 stll 0.554846137 stll 0.555057477 ----------------------------------------------------------- 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 =3D 9000 # Integer(ARGV.shift || 1) x =3D Array.new(n) y =3D Array.new(n, 0) n.times{|bi| x[bi] =3D bi + 1 } (0 .. 999).each do |e| (n-1).step(0,-1) do |bi| y[bi] +=3D x.at(bi) end end # puts "#{y.first} #{y.last}" orig 0.716432331 orig 0.715614862 orig 0.718187026 orig 0.715615418 orig 0.716560232 orig 0.719680592 orig 0.716808351 orig 0.715400045 orig 0.717318291 orig 0.716128422 stll 0.722933867 stll 0.723459141 stll 1.01009105 stll 1.05958547 stll 0.723921387 stll 1.018041186 stll 0.820268848 stll 0.728892185 stll 0.728845082 stll 0.726623785 ----------------------------------------------------------- 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] =3D=3D 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 =3D 2 * item depth -=3D 1 [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, de= pth)] else [nil, item, nil] end end max_depth =3D 16 # ARGV[0].to_i min_depth =3D 4 max_depth =3D min_depth + 2 if min_depth + 2 > max_depth stretch_depth =3D max_depth + 1 stretch_tree =3D bottom_up_tree(0, stretch_depth) puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_= tree)}" stretch_tree =3D nil long_lived_tree =3D bottom_up_tree(0, max_depth) min_depth.step(max_depth + 1, 2) do |depth| iterations =3D 2**(max_depth - depth + min_depth) check =3D 0 for i in 1..iterations temp_tree =3D bottom_up_tree(i, depth) check +=3D item_check(temp_tree) temp_tree =3D bottom_up_tree(-i, depth) check +=3D 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_live= d_tree)}" undef puts alias puts puts_orig orig 5.891852595 orig 5.85857463 orig 5.886513007 orig 5.904337825 orig 6.007118055 orig 5.832122029 orig 5.817885089 orig 5.865527204 orig 6.11444961 orig 5.900852034 stll 5.841628543 stll 5.848832941 stll 5.842604198 stll 5.816352106 stll 5.914531149 stll 5.821454501 stll 5.864819026 stll 5.82034879 stll 5.78314775 stll 5.96197454 ----------------------------------------------------------- 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 =3D "hello\n" i =3D 0 while i<10 i +=3D 1 hello =3D '' 4_000_000.times do |e| hello << STUFF end end # puts hello.length orig 3.145572464 orig 3.14750577 orig 3.152418716 orig 3.661567167 orig 3.183339491 orig 3.170945435 orig 3.388805977 orig 3.156055341 orig 3.357375794 orig 3.14938203 stll 3.131218652 stll 3.163337176 stll 3.204333685 stll 3.121685686 stll 3.129380278 stll 3.122056144 stll 3.124002248 stll 3.140635879 stll 3.220535497 stll 3.169139827 ----------------------------------------------------------- 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 =3D open(File.join(File.dirname($0), 'wc.input'), 'rb') nl =3D nw =3D nc =3D 0 while true tmp =3D input.read(4096) or break data =3D tmp << (input.gets || "") nc +=3D data.length nl +=3D data.count("\n") ((data.strip! || data).tr!("\n", " ") || data).squeeze! nw +=3D data.count(" ") + 1 end # STDERR.puts "#{nl} #{nw} #{nc}" orig 0.242391291 orig 0.239844531 orig 0.239700652 orig 0.240641664 orig 0.240109531 orig 0.241933466 orig 0.239628769 orig 0.239354057 orig 0.240767827 orig 0.220111057 stll 0.197886702 stll 0.197439675 stll 0.197293019 stll 0.199392232 stll 0.198683854 stll 0.197303157 stll 0.197314665 stll 0.197404594 stll 0.19820777 stll 0.197466916 ----------------------------------------------------------- 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 =3D 0 $LO =3D 0 NUM =3D 250000 # Integer(ARGV[0] || 1) class Lo_Exception < Exception def initialize(num) @value =3D num end end class Hi_Exception < Exception def initialize(num) @value =3D 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 =3D $HI + 1 end end def lo_function(num) begin blowup(num) rescue Lo_Exception $LO =3D $LO + 1 end end def blowup(num) if num % 2 =3D=3D 0 raise Lo_Exception.new(num) else raise Hi_Exception.new(num) end end i =3D 1 max =3D NUM+1 while i < max i +=3D 1 some_function(i+1) end orig 0.27459704 orig 0.282408741 orig 0.279051681 orig 0.276141397 orig 0.279595338 orig 0.274870568 orig 0.286747379 orig 0.27522475 orig 0.29289278 orig 0.278606696 stll 0.296178192 stll 0.275072498 stll 0.27512703 stll 0.275032342 stll 0.275854473 stll 0.27558595 stll 0.273236387 stll 0.278263372 stll 0.280499338 stll 0.290462425 ----------------------------------------------------------- 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 =3D 0, n-1, n, 0 count =3D (1..n).to_a perm =3D (1..n).to_a while true if check < 30 puts "#{perm}" check +=3D 1 end while r !=3D 1 count[r-1] =3D r r -=3D 1 end if perm[0] !=3D 1 and perm[m] !=3D n perml =3D perm.clone #.dup flips =3D 0 while (k =3D perml.first ) !=3D 1 perml =3D perml.slice!(0, k).reverse + perml flips +=3D 1 end maxFlips =3D flips if flips > maxFlips end while true if r=3D=3Dn then return maxFlips end perm.insert r,perm.shift break if (count[r] -=3D 1) > 0 r +=3D 1 end end end def puts *args end N =3D 9 # (ARGV[0] || 1).to_i puts "Pfannkuchen(#{N}) =3D #{fannkuch(N)}" orig 0.99656016 orig 0.997722458 orig 0.993261332 orig 1.012012197 orig 1.032322957 orig 0.998555259 orig 0.9905474 orig 0.98366331 orig 1.018624582 orig 1.027585325 stll 0.993587482 stll 1.029757339 stll 1.021017374 stll 0.997894093 stll 1.008250871 stll 1.012816448 stll 1.037534666 stll 1.006494168 stll 0.991196374 stll 1.051552952 ----------------------------------------------------------- so_fasta # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura $last =3D 42.0 def gen_random (max,im=3D139968,ia=3D3877,ic=3D29573) (max * ($last =3D ($last * ia + ic) % im)) / im end alu =3D "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" iub =3D [ ["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 =3D [ ["a", 0.3029549426680], ["c", 0.1979883004921], ["g", 0.1975473066391], ["t", 0.3015094502008], ] def make_repeat_fasta(id, desc, src, n) puts ">#{id} #{desc}" v =3D nil width =3D 60 l =3D src.length s =3D 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 =3D nil,nil width =3D 60 chunk =3D 1 * width prob =3D 0.0 table.each{|v| v[1]=3D (prob +=3D v[1])} for i in 1..(n/width) puts((1..width).collect{ rand =3D gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end if n%width !=3D 0 puts((1..(n%width)).collect{ rand =3D gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end end n =3D (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.626379653 orig 1.604243419 orig 1.608287118 orig 1.610960882 orig 1.619263969 orig 1.659891248 orig 1.606374795 orig 1.612020157 orig 1.667336899 orig 1.617827365 stll 1.861029118 stll 1.596523452 stll 1.605929241 stll 1.603162676 stll 1.617902462 stll 1.596778535 stll 1.747227256 stll 1.624631813 stll 1.596906256 stll 1.594713807 ----------------------------------------------------------- so_k_nucleotide # The Computer Language Shootout # http://shootout.alioth.debian.org # # contributed by jose fco. gonzalez # modified by Sokolov Yura seq =3D String.new def frecuency( seq,length ) n, table =3D seq.length - length + 1, Hash.new(0) f, i =3D nil, nil (0 ... length).each do |f| (f ... n).step(length) do |i| table[seq[i,length]] +=3D 1 end end [n,table] end def sort_by_freq( seq,length ) n,table =3D frecuency( seq,length ) a, b, v =3D nil, nil, nil table.sort{|a,b| b[1] <=3D> 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 =3D frecuency( seq,s.length ) puts "#{table[s].to_s}\t#{s.upcase}" end input =3D open(File.join(File.dirname($0), 'fasta.output.100000'), 'rb') line =3D input.gets while line !~ /^>THREE/ line =3D input.gets while (line !~ /^>/) & line do seq << line.chomp line =3D 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.004566888 orig 1.000403766 orig 1.013398124 orig 1.008655269 orig 1.004949563 orig 1.007553872 orig 1.00565489 orig 1.006228219 orig 0.999932032 orig 1.280733682 stll 1.006863257 stll 1.010804323 stll 1.006856365 stll 1.021802051 stll 1.002110227 stll 1.013540483 stll 1.007242235 stll 1.012412313 stll 1.008362609 stll 1.009553163 ----------------------------------------------------------- so_lists #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby NUM =3D 300 SIZE =3D 10000 def test_lists() # create a list of integers (Li1) from 1 to SIZE li1 =3D (1..SIZE).to_a # copy the list to li2 (not by individual items) li2 =3D li1.dup # remove each individual item from left side of li2 and # append to right side of li3 (preserving order) li3 =3D 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] !=3D SIZE then p "not SIZE" 0 else # compare li1 and li2 for equality if li1 !=3D li2 then return(0) else # return the length of the list li1.length end end end i =3D 0 while i LIMIT_SQUARED escape =3D true break end end byte_acc =3D (byte_acc << 1) | (escape ? 0b0 : 0b1) bit_num +=3D 1 # Code is very similar for these cases, but using separate blocks # ensures we skip the shifting when it's unnecessary, which is most cas= es. if (bit_num =3D=3D 8) print byte_acc.chr byte_acc =3D 0 bit_num =3D 0 elsif (x =3D=3D count_size) byte_acc <<=3D (8 - bit_num) print byte_acc.chr byte_acc =3D 0 bit_num =3D 0 end end end orig 1.979842828 orig 1.986014054 orig 2.023256356 orig 1.990052777 orig 2.004414585 orig 1.989482749 orig 2.00374384 orig 2.005260208 orig 1.973930571 orig 2.013561508 stll 1.983405369 stll 1.986018375 stll 1.981057158 stll 1.990895433 stll 1.998027297 stll 1.980012879 stll 2.000246329 stll 1.988311323 stll 2.068660796 stll 1.988520077 ----------------------------------------------------------- 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 =3D 60 #Integer(ARGV.shift || 1) size =3D 40 def mkmatrix(rows, cols) count =3D 1 mx =3D Array.new(rows) (0 .. (rows - 1)).each do |bi| row =3D Array.new(cols, 0) (0 .. (cols - 1)).each do |j| row[j] =3D count count +=3D 1 end mx[bi] =3D row end mx end def mmult(rows, cols, m1, m2) m3 =3D Array.new(rows) (0 .. (rows - 1)).each do |bi| row =3D Array.new(cols, 0) (0 .. (cols - 1)).each do |j| val =3D 0 (0 .. (cols - 1)).each do |k| val +=3D m1.at(bi).at(k) * m2.at(k).at(j) end row[j] =3D val end m3[bi] =3D row end m3 end m1 =3D mkmatrix(size, size) m2 =3D mkmatrix(size, size) mm =3D Array.new n.times do mm =3D mmult(size, size, m1, m2) end # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}" orig 0.500874477 orig 0.484887281 orig 0.508492887 orig 0.49274288 orig 0.499600926 orig 0.533587423 orig 0.537606671 orig 0.494616717 orig 0.486548428 orig 0.487992105 stll 0.488608283 stll 0.492753145 stll 0.489930145 stll 0.492269239 stll 0.510433561 stll 0.490049011 stll 0.501774228 stll 0.509093734 stll 0.498486931 stll 0.491265322 ----------------------------------------------------------- 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/j= ava/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 parti= cular 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 whe= ther it is an even or # odd row being mapped from @@rotation_even_adder =3D { :west =3D> -1, :east =3D> 1, :nw =3D> -7, :ne= =3D> -6, :sw =3D> 5, :se =3D> 6 } @@rotation_odd_adder =3D { :west =3D> -1, :east =3D> 1, :nw =3D> -6, :ne = =3D> -5, :sw =3D> 6, :se =3D> 7 } def initialize( directions ) @even_offsets, @odd_offsets =3D normalize_offsets( get_values( directio= ns )) @even_mask =3D mask_for_offsets( @even_offsets) @odd_mask =3D mask_for_offsets( @odd_offsets) @start_masks =3D 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. i= f either of these # is true the piece cannot be placed 0.upto(59) do | offset | mask =3D is_even(offset) ? (@even_mask << offset) : (@odd_mask << off= set) if (blank_board & mask =3D=3D 0 && !prunable(blank_board | mask, 0, t= rue)) then imask =3D compute_required( mask, offset) @start_masks[offset] =3D [ mask, imask, imask | mask ] else @start_masks[offset] =3D false end end end def compute_required( mask, offset ) board =3D blank_board 0.upto(offset) { | i | board |=3D 1 << i } board |=3D mask return 0 if (!prunable(board | mask, offset)) board =3D flood_fill(board,58) count =3D 0 imask =3D 0 0.upto(59) do | i | if (board[i] =3D=3D 0) then imask |=3D (1 << i) count +=3D 1 end end (count > 0 && count < 5) ? imask : 0 end def flood_fill( board, location) return board if (board[location] =3D=3D 1) board |=3D 1 << location row, col =3D location.divmod(6) board =3D flood_fill( board, location - 1) if (col > 0) board =3D flood_fill( board, location + 1) if (col < 4) if (row % 2 =3D=3D 0) then board =3D flood_fill( board, location - 7) if (col > 0 && row > 0) board =3D flood_fill( board, location - 6) if (row > 0) board =3D flood_fill( board, location + 6) if (row < 9) board =3D flood_fill( board, location + 5) if (col > 0 && row < 9) else board =3D flood_fill( board, location - 5) if (col < 4 && row > 0) board =3D flood_fill( board, location - 6) if (row > 0) board =3D flood_fill( board, location + 6) if (row < 9) board =3D 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 rot= ation (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 a= n 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 =3D values.min even_min =3D is_even(min) other_min =3D even_min ? min + 6 : min + 7 other_values =3D 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 =3D 0 offsets.each { | value | mask =3D mask + ( 1 << value ) } mask end # finds a "safe" position that a position as described by a list of direc= tions can be placed # without falling off any edge of the board. the values returned a locat= ion to place the first piece # at so it will fit after making the described moves def start_adjust( directions ) south =3D east =3D 0; directions.each do | direction | east +=3D 1 if ( direction =3D=3D :sw || direction =3D=3D :nw || dire= ction =3D=3D :west ) south +=3D 1 if ( direction =3D=3D :nw || direction =3D=3D :ne ) end south * 6 + east end # given a set of directions places the piece (as defined by a set of dire= ctions) on the board at # a location that will not take it off the edge def get_values ( directions ) start =3D start_adjust(directions) values =3D [ start ] directions.each do | direction | if (start % 12 >=3D 6) then start +=3D @@rotation_odd_adder[direction] else start +=3D @@rotation_even_adder[direction] end values +=3D [ start ] end # some moves take you back to an existing location, we'll strip duplica= tes 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 =3D { :west =3D> :west, :east =3D> :east, :nw =3D> :sw, = :ne =3D> :se, :sw =3D> :nw, :se =3D> :ne } @@rotate_converter =3D { :west =3D> :nw, :east =3D> :se, :nw =3D> :ne, :n= e =3D> :east, :sw =3D> :west, :se =3D> :sw } def initialize( directions, type ) @type =3D type @rotations =3D Array.new(); @map =3D {} 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 =3D Array.new(); 0.upto(59) do | i | even =3D true @masks[i] =3D @rotations.collect do | rotation | mask =3D rotation.start_masks[i] @map[mask[0]] =3D [ 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 not= ation is six wide (padded) def fill_string( board_string) location, rotation =3D @map[@placed] rotation.offsets(location).each do | offset | row, col =3D offset.divmod(6) board_string[ row*5 + col, 1 ] =3D @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 1= s 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 =3D> [ 0b01100, 2, 0b01100 ], [ 0b00001= , 1, 0b00001] # 0b01010 =3D> [ 0b10000, 1, 0b10000 ], [ 0b00100= , 1, 0b00100 ], [ 0b00001, 1, 0b00001] # 0b10001 =3D> [ 0b01110, 3, 0b01110 ] def create_collector_support odd_map =3D [0b11, 0b110, 0b1100, 0b11000, 0b10000] even_map =3D [0b1, 0b11, 0b110, 0b1100, 0b11000] all_odds =3D Array.new(0b100000) all_evens =3D Array.new(0b100000) bit_counts =3D Array.new(0b100000) new_regions =3D Array.new(0b100000) 0.upto(0b11111) do | i | bit_count =3D odd =3D even =3D 0 0.upto(4) do | bit | if (i[bit] =3D=3D 1) then bit_count +=3D 1 odd |=3D odd_map[bit] even |=3D even_map[bit] end end all_odds[i] =3D odd all_evens[i] =3D even bit_counts[i] =3D bit_count new_regions[i] =3D create_regions( i) end $converter =3D [] 10.times { | row | $converter.push((row % 2 =3D=3D 0) ? all_evens : all_o= dds) } $bit_counts =3D bit_counts $regions =3D new_regions.collect { | set | set.collect { | value | [ valu= e, bit_counts[value], value] } } end # determines if a board is punable, meaning that there is no possibility th= at 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 f= ormat) # location -- starting location, everything above and to the left is alre= ady 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 it= erates a row at a time # maintainng counts of active open areas (kept in the collector array) e= ach 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 computa= tion 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 =3D false) collectors =3D [] # 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 =3D $regions[(board >> (row_on * 6)) & 0b11111] converter =3D $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 coll= ectors initial_collector_count =3D 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 collect= or regions.each do | region | collector_found =3D nil region_mask =3D region[2] initial_collector_count.times do | collector_num | collector =3D collectors[collector_num] if (collector) then collector_mask =3D collector[0] if (collector_mask & region_mask !=3D 0) then if (collector_found) then collector_found[0] |=3D collector_mask collector_found[1] +=3D collector[1] collector_found[2] |=3D collector[2] collectors[collector_num] =3D nil else collector_found =3D collector collector[1] +=3D region[1] collector[2] |=3D region_mask end end end end if (collector_found =3D=3D 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 multi= ple 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 bas= ed n the matched bits # and have [2] cleared out for the next cycle. collectors.length.times do | collector_num | collector =3D collectors[collector_num] if (collector) then if (collector[2] =3D=3D 0) then return true if (collector[1] % 5 !=3D 0) collectors[collector_num] =3D nil else # if a collector matches all bits in the row then we can return u= nprunable 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 t= his 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 ot= her time this algorithm is used). return false if (collector[2] =3D=3D 0b11111 && !slotting) collector[0] =3D converter[collector[2]] collector[2] =3D 0 end end end # get rid of all the empty converters for the next round collectors.compact! end return false if (collectors.length <=3D 1) # 1 collector or less and the = region is fine collectors.any? { | collector | (collector[1] % 5) !=3D 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 =3D [] cur_region =3D 0 5.times do | bit | if (value[bit] =3D=3D 0) then cur_region |=3D 1 << bit else if (cur_region !=3D 0 ) then regions.push( cur_region) cur_region =3D 0; end end end regions.push(cur_region) if (cur_region !=3D 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 sol= utions that are not already found # as an inverse. The inverse will ALWAYS be 3 one of the piece configura= tions that is exactly 3 rotations away # (an odd number). Checking even vs odd then produces a higher probabili= ty 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 =3D blank_board (@pieces.length-1).times do piece =3D @pieces.shift piece.masks[0].each do | mask, imask, cmask | if ((rotation_skip +=3D 1) % 2 =3D=3D 0) then piece.placed =3D mask find( 1, 1, board | mask) end end @pieces.push(piece) end piece =3D @pieces.shift @pieces.push(piece) end # the normail find routine, iterates through the available pieces, checks a= ll 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] =3D=3D 1 start_location +=3D 1 end @pieces.length.times do piece =3D @pieces.shift piece.masks[start_location].each do | mask, imask, cmask | if ( board & cmask =3D=3D imask) then piece.placed =3D mask if (placed =3D=3D 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 =3D=3D 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 strin= g, adding both to # the list (hash) of solutions if they are unique. def add_board board_string =3D "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/wor= st board def save( board_string) if (@all_boards[board_string] =3D=3D nil) then @min_board =3D board_string if (board_string < @min_board) @max_board =3D board_string if (board_string > @max_board) @all_boards.store(board_string,true) @boards_found +=3D 1 # the exit motif is a time saver. Ideally the function should return, = but those tests # take noticeable time (performance). if (@boards_found =3D=3D @stop_count) then print_results exit(0) end end end ## ## MAIN BODY :) ## create_collector_support @pieces =3D [ 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 =3D Array.new( @pieces) @min_board =3D "99999999999999999999999999999999999999999999999999" @max_board =3D "00000000000000000000000000000000000000000000000000" @stop_count =3D ARGV[0].to_i || 2089 @all_boards =3D {} @boards_found =3D 0 find_all ######## DO IT!!! orig 2.64489358 orig 2.665539128 orig 2.620766875 orig 2.64559136 orig 2.667070644 orig 2.615702788 orig 2.634790016 orig 2.676334988 orig 2.629919232 orig 2.617883585 stll 2.643250652 stll 2.655673084 stll 2.689109941 stll 2.819435765 stll 2.656473882 stll 2.683216279 stll 2.725329669 stll 2.646512151 stll 2.651052236 stll 2.651709693 ----------------------------------------------------------- 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 =3D 4 * Math::PI**2 DAYS_PER_YEAR =3D 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 =3D x, y, z @vx, @vy, @vz =3D vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_Y= EAR @mass =3D mass * SOLAR_MASS end def move_from_i(bodies, nbodies, dt, i) while i < nbodies b2 =3D bodies[i] dx =3D @x - b2.x dy =3D @y - b2.y dz =3D @z - b2.z distance =3D Math.sqrt(dx * dx + dy * dy + dz * dz) mag =3D dt / (distance * distance * distance) b_mass_mag, b2_mass_mag =3D @mass * mag, b2.mass * mag @vx -=3D dx * b2_mass_mag @vy -=3D dy * b2_mass_mag @vz -=3D dz * b2_mass_mag b2.vx +=3D dx * b_mass_mag b2.vy +=3D dy * b_mass_mag b2.vz +=3D dz * b_mass_mag i +=3D 1 end @x +=3D dt * @vx @y +=3D dt * @vy @z +=3D dt * @vz end end def energy(bodies) e =3D 0.0 nbodies =3D bodies.size for i in 0 ... nbodies b =3D bodies[i] e +=3D 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz) for j in (i + 1) ... nbodies b2 =3D bodies[j] dx =3D b.x - b2.x dy =3D b.y - b2.y dz =3D b.z - b2.z distance =3D Math.sqrt(dx * dx + dy * dy + dz * dz) e -=3D (b.mass * b2.mass) / distance end end e end def offset_momentum(bodies) px, py, pz =3D 0.0, 0.0, 0.0 for b in bodies m =3D b.mass px +=3D b.vx * m py +=3D b.vy * m pz +=3D b.vz * m end b =3D bodies[0] b.vx =3D - px / SOLAR_MASS b.vy =3D - py / SOLAR_MASS b.vz =3D - pz / SOLAR_MASS end BODIES =3D [ # 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 =3D 200_000 # ARGV[0] n =3D Integer(init) offset_momentum(BODIES) puts "%.9f" % energy(BODIES) nbodies =3D BODIES.size dt =3D 0.01 n.times do i =3D 0 while i < nbodies b =3D BODIES[i] b.move_from_i(BODIES, nbodies, dt, i + 1) i +=3D 1 end end puts "%.9f" % energy(BODIES) orig 1.205101985 orig 1.213859787 orig 1.205128418 orig 1.391464894 orig 1.326758401 orig 1.199627727 orig 1.45721871 orig 1.208749139 orig 1.199151646 orig 1.200151241 stll 1.20549877 stll 1.237723323 stll 1.204646758 stll 1.199548993 stll 1.195648843 stll 1.198679314 stll 1.197062663 stll 1.210142232 stll 1.243288638 stll 1.319684736 ----------------------------------------------------------- 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 =3D 16 # Integer(ARGV.shift || 1) x =3D 0 n.times do n.times do n.times do n.times do n.times do n.times do x +=3D 1 end end end end end end # puts x orig 0.884004457 orig 0.905090802 orig 0.871943968 orig 0.870676388 orig 0.908360449 orig 0.932598348 orig 1.059668395 orig 1.26015312 orig 0.870940727 orig 0.885396989 stll 0.887870576 stll 1.171482791 stll 0.908446414 stll 0.88783285 stll 0.877407234 stll 0.92061022 stll 0.869538448 stll 0.896780013 stll 0.896127852 stll 0.875915198 ----------------------------------------------------------- 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 =3D Flags.dup[0,m] count =3D 0 pmax =3D m - 1 p =3D 2 while p <=3D pmax unless flags[p].zero? count +=3D 1 mult =3D p while mult <=3D pmax flags[mult] =3D 0 mult +=3D p end end p +=3D 1 end count end n =3D 9 # (ARGV[0] || 2).to_i Flags =3D ("\x1" * ( 2 ** n * 10_000)).unpack("c*") n.downto(n-2) do |exponent| break if exponent < 0 m =3D (1 << exponent) * 10_000 # m =3D (2 ** exponent) * 10_000 count =3D sieve(m) printf "Primes up to %8d %8d\n", m, count end orig 1.433350772 orig 1.422841423 orig 1.434855136 orig 1.422749093 orig 1.424615379 orig 1.445042906 orig 1.433590631 orig 1.426340732 orig 1.419519729 orig 1.422578648 stll 1.435229006 stll 1.436386252 stll 1.454652324 stll 1.43760086 stll 1.432428185 stll 1.434775625 stll 1.439618084 stll 1.459607035 stll 1.439808637 stll 1.442253853 ----------------------------------------------------------- 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 =3D 3 BitsPerChar =3D 1 << CharExponent LowMask =3D BitsPerChar - 1 def sieve(m) items =3D "\xFF" * ((m / BitsPerChar) + 1) masks =3D "" BitsPerChar.times do |b| masks << (1 << b).chr end count =3D 0 pmax =3D m - 1 2.step(pmax, 1) do |p| if items[p >> CharExponent][p & LowMask] =3D=3D 1 count +=3D 1 p.step(pmax, p) do |mult| a =3D mult >> CharExponent b =3D mult & LowMask items[a] -=3D masks[b] if items[a][b] !=3D 0 end end end count end n =3D 9 # (ARGV[0] || 2).to_i n.step(n - 2, -1) do |exponent| break if exponent < 0 m =3D 2 ** exponent * 10_000 count =3D sieve(m) printf "Primes up to %8d %8d\n", m, count end orig 1.885272314 orig 1.894371983 orig 1.881578513 orig 2.282154784 orig 1.970788897 orig 1.88036627 orig 1.917455219 orig 1.880669436 orig 1.880472597 orig 1.929477201 stll 1.98571179 stll 1.909510103 stll 1.885918757 stll 1.886175113 stll 1.936036665 stll 1.884183483 stll 1.936353317 stll 1.886282141 stll 1.936303274 stll 1.886593089 ----------------------------------------------------------- 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 =3D start_state end def value @bool end def activate @bool =3D !@bool self end end class NthToggle < Toggle def initialize(start_state, max_counter) super start_state @count_max =3D max_counter @counter =3D 0 end def activate @counter +=3D 1 if @counter >=3D @count_max @bool =3D !@bool @counter =3D 0 end self end end n =3D 1500000 # (ARGV.shift || 1).to_i toggle =3D Toggle.new 1 5.times do toggle.activate.value ? 'true' : 'false' end n.times do toggle =3D Toggle.new 1 end ntoggle =3D NthToggle.new 1, 3 8.times do ntoggle.activate.value ? 'true' : 'false' end n.times do ntoggle =3D NthToggle.new 1, 3 end orig 0.58789362 orig 0.59184246 orig 0.587967287 orig 0.588134718 orig 0.589231962 orig 0.600176239 orig 0.587345601 orig 0.589692602 orig 0.590391874 orig 0.588790516 stll 0.617989568 stll 0.599776789 stll 0.600555451 stll 0.599688356 stll 0.636933354 stll 0.917953399 stll 0.602737827 stll 0.599820535 stll 0.599344116 stll 0.601595503 ----------------------------------------------------------- so_partial_sums n =3D 2_500_000 # (ARGV.shift || 1).to_i alt =3D 1.0 ; s0 =3D s1 =3D s2 =3D s3 =3D s4 =3D s5 =3D s6 =3D s7 =3D s8 = =3D 0.0 1.upto(n) do |d| d =3D d.to_f ; d2 =3D d * d ; d3 =3D d2 * d ; ds =3D Math.sin(d) ; dc =3D= Math.cos(d) s0 +=3D (2.0 / 3.0) ** (d - 1.0) s1 +=3D 1.0 / Math.sqrt(d) s2 +=3D 1.0 / (d * (d + 1.0)) s3 +=3D 1.0 / (d3 * ds * ds) s4 +=3D 1.0 / (d3 * dc * dc) s5 +=3D 1.0 / d s6 +=3D 1.0 / d2 s7 +=3D alt / d s8 +=3D alt / (2.0 * d - 1.0) alt =3D -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.880699844 orig 1.885463321 orig 1.871235188 orig 1.776139242 orig 1.768804882 orig 1.813928255 orig 1.798474237 orig 1.769855196 orig 1.772887237 orig 1.774969887 stll 1.755212649 stll 1.765916881 stll 1.753125487 stll 1.793198484 stll 1.754066969 stll 1.756901637 stll 1.75644061 stll 1.791233392 stll 1.972476254 stll 1.884114605 ----------------------------------------------------------- so_pidigits # The Great Computer Language Shootout # http://shootout.alioth.debian.org/ # # contributed by Gabriele Renzi class PiDigitSpigot def initialize() @z =3D Transformation.new 1,0,0,1 @x =3D Transformation.new 0,0,0,0 @inverse =3D Transformation.new 0,0,0,0 end def next! @y =3D @z.extract(3) if safe? @y @z =3D produce(@y) @y else @z =3D consume @x.next!() next!() end end def safe?(digit) digit =3D=3D @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 =3D q,r,s,t,0 end def next!() @q =3D @k =3D @k + 1 @r =3D 4 * @k + 2 @s =3D 0 @t =3D 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 =3D 10 n =3D 2_500 # Integer(ARGV[0]) j =3D 0 digits =3D PiDigitSpigot.new while n > 0 if n >=3D WIDTH WIDTH.times {print digits.next!} j +=3D WIDTH else n.times {print digits.next!} (WIDTH-n).times {print " "} j +=3D n end puts "\t:"+j.to_s n -=3D WIDTH end orig 0.957060099 orig 0.957411888 orig 0.963470988 orig 0.958903022 orig 0.967337511 orig 0.962384705 orig 0.958645076 orig 0.95770352 orig 0.955135655 orig 0.961775851 stll 0.9429389 stll 0.943606296 stll 0.949029438 stll 0.943701328 stll 0.944859347 stll 0.942171759 stll 0.941467939 stll 0.943824571 stll 0.94144008 stll 0.947744497 ----------------------------------------------------------- so_random # from http://www.bagley.org/~doug/shootout/bench/random/random.ruby IM =3D 139968.0 IA =3D 3877.0 IC =3D 29573.0 $last =3D 42.0 def gen_random(max) (max * ($last =3D ($last * IA + IC) % IM)) / IM end N =3D 3_000_000 i =3D 0 while i/ if seq.length !=3D 0 revcomp(seq.join) seq=3DArray.new end puts $_ else $_.sub(/\n/,'') seq.push $_ end end revcomp(seq.join) orig 1.19546514 orig 1.183278023 orig 1.212173001 orig 1.087653349 orig 1.20140735 orig 1.183987459 orig 1.196346604 orig 1.186763176 orig 1.094528627 orig 1.189048228 stll 1.141821171 stll 1.142904285 stll 1.178747042 stll 1.181916333 stll 1.154907879 stll 1.214846227 stll 1.151054146 stll 1.185621045 stll 1.189607442 stll 1.215448142 ----------------------------------------------------------- so_sieve # from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby num =3D 500 count =3D i =3D j =3D 0 flags0 =3D Array.new(8192,1) k =3D 0 while k < num k +=3D 1 count =3D 0 flags =3D flags0.dup i =3D 2 while i<8192 i +=3D 1 if flags[i] # remove all multiples of prime: i j =3D i*i while j < 8192 j +=3D i flags[j] =3D nil end count +=3D 1 end end end count orig 0.470463395 orig 0.463910925 orig 0.464827161 orig 0.463764632 orig 0.464697532 orig 0.463857276 orig 0.464311539 orig 0.477877842 orig 0.463772041 orig 0.464269611 stll 0.469503609 stll 0.469179384 stll 0.469393566 stll 0.469894459 stll 0.469383854 stll 0.468934437 stll 0.469077631 stll 0.469599363 stll 0.469048302 stll 0.470137266 ----------------------------------------------------------- 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 =3D nil, nil (0..u.length-1).collect { |i| v =3D 0 for j in 0..u.length-1 v +=3D eval_A(i,j)*u[j] end v } end def eval_At_times_u(u) v, i =3D nil, nil (0..u.length-1).collect{|i| v =3D 0 for j in 0..u.length-1 v +=3D 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 =3D 500 # ARGV[0].to_i u=3D[1]*n for i in 1..10 v=3Deval_AtA_times_u(u) u=3Deval_AtA_times_u(v) end vBv=3D0 vv=3D0 for i in 0..n-1 vBv +=3D u[i]*v[i] vv +=3D v[i]*v[i] end str =3D "%0.9f" % (Math.sqrt(vBv/vv)), "\n" # print str orig 1.776248853 orig 1.734098752 orig 1.726329029 orig 1.717729015 orig 1.723574111 orig 1.858471666 orig 1.738485008 orig 1.71906145 orig 1.717009932 orig 1.739294577 stll 1.723627502 stll 1.727801841 stll 1.732547779 stll 1.721272043 stll 1.720609006 stll 1.719929987 stll 1.724219175 stll 1.892292358 stll 1.879054572 stll 1.765989043 ----------------------------------------------------------- vm1_attr_ivar class C attr_reader :a, :b def initialize @a =3D nil @b =3D nil end end obj =3D C.new i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 j =3D obj.a k =3D obj.b end orig 1.326750513 orig 1.281467312 orig 1.341676341 orig 1.154036421 orig 1.088513305 orig 1.362177061 orig 1.237257317 orig 1.186542107 orig 1.202354104 orig 1.087300805 stll 1.089515037 stll 1.096151008 stll 1.095826107 stll 1.09110839 stll 1.08988974 stll 1.086924157 stll 1.08689725 stll 1.087652692 stll 1.086958201 stll 1.086968367 ----------------------------------------------------------- vm1_attr_ivar_set class C attr_accessor :a, :b def initialize @a =3D nil @b =3D nil end end obj =3D C.new i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 obj.a =3D 1 obj.b =3D 2 end orig 1.406125838 orig 1.420390519 orig 1.410263949 orig 1.456576401 orig 1.453218966 orig 1.412157335 orig 1.420401316 orig 1.406924099 orig 1.411840276 orig 1.408635788 stll 1.413086011 stll 1.410921039 stll 1.515902883 stll 1.42461814 stll 1.49368099 stll 1.593859797 stll 1.731580157 stll 1.536495996 stll 1.59667807 stll 1.40971823 ----------------------------------------------------------- vm1_block def m yield end i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 m{ } end orig 2.004619915 orig 1.984161039 orig 2.000238866 orig 1.994394683 orig 1.986587118 orig 2.027757692 orig 2.048867635 orig 1.981987365 orig 1.986718518 orig 2.049096827 stll 1.985284802 stll 2.076749991 stll 1.987910221 stll 1.994191389 stll 1.988661818 stll 1.986830653 stll 2.16810906 stll 1.990068097 stll 2.424476009 stll 2.438980967 ----------------------------------------------------------- vm1_const Const =3D 1 i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 j =3D Const k =3D Const end orig 0.724011415 orig 0.751993343 orig 0.828428348 orig 0.724765577 orig 0.723729441 orig 0.876904781 orig 0.762510992 orig 0.727887555 orig 0.724300319 orig 0.723454546 stll 0.720973701 stll 0.721035578 stll 0.721423021 stll 0.721296312 stll 0.721248332 stll 0.724508718 stll 0.720067769 stll 0.721091193 stll 0.720684421 stll 0.720590542 ----------------------------------------------------------- vm1_ensure i =3D 0 while i<30_000_000 # benchmark loop 1 i +=3D 1 begin begin ensure end ensure end end orig 0.510265405 orig 0.511039576 orig 0.510855647 orig 0.510571646 orig 0.510487244 orig 0.510646966 orig 0.510903815 orig 0.511170774 orig 0.510245093 orig 0.510242364 stll 0.513740223 stll 0.513880149 stll 0.513927762 stll 0.513652705 stll 0.513784976 stll 0.513959367 stll 0.513939594 stll 0.513989961 stll 0.513810522 stll 0.513645247 ----------------------------------------------------------- vm1_float_simple i =3D 0.0; f =3D 0.0 while i<30_000_000 i +=3D 1 f +=3D 0.1; f -=3D 0.1 f +=3D 0.1; f -=3D 0.1 f +=3D 0.1; f -=3D 0.1 end orig 4.352794815 orig 4.427100234 orig 4.357426692 orig 4.242957955 orig 5.749445486 orig 4.861683109 orig 4.611913164 orig 4.248991524 orig 4.310098038 orig 4.331423845 stll 4.40533171 stll 4.385436746 stll 4.539163247 stll 4.451554309 stll 5.371444941 stll 5.058826984 stll 4.394677752 stll 4.399262148 stll 4.622233003 stll 4.341218332 ----------------------------------------------------------- vm1_gc_short_lived i =3D 0 while i<30_000_000 # while loop 1 a =3D '' # short-lived String b =3D '' c =3D '' d =3D '' e =3D '' f =3D '' i+=3D1 end orig 9.299003918 orig 9.607103822 orig 9.52348325 orig 9.351952746 orig 9.166694274 orig 9.154672515 orig 9.241831242 orig 9.222188708 orig 9.097087049 orig 9.083368277 stll 8.979892772 stll 8.948615418 stll 8.94358949 stll 8.977953226 stll 8.930222551 stll 8.966036805 stll 9.165879242 stll 9.162806971 stll 8.928880773 stll 8.908029302 ----------------------------------------------------------- vm1_gc_short_with_complex_long def nested_hash h, n if n =3D=3D 0 '' else 10.times{ h[Object.new] =3D nested_hash(h, n-1) } end end long_lived =3D Hash.new nested_hash long_lived, 6 GC.start GC.start i =3D 0 while i<30_000_000 # while loop 1 a =3D '' # short-lived String b =3D '' c =3D '' d =3D '' e =3D '' f =3D '' i+=3D1 end orig 10.979590732 orig 11.069026647 orig 10.989757024 orig 10.980927352 orig 10.92604894 orig 11.045978772 orig 11.032459172 orig 10.968647442 orig 11.022738346 orig 11.050070382 stll 11.108989548 stll 10.895239351 stll 10.893372779 stll 11.098307264 stll 11.264270621 stll 10.939747221 stll 10.948628476 stll 10.922754727 stll 10.989071546 stll 10.884562285 ----------------------------------------------------------- vm1_gc_short_with_long long_lived =3D Array.new(1_000_000){|i| "#{i}"} GC.start GC.start i =3D 0 while i<30_000_000 # while loop 1 a =3D '' # short-lived String b =3D '' c =3D '' d =3D '' e =3D '' f =3D '' i+=3D1 end orig 9.85388492 orig 9.862436618 orig 9.853143666 orig 9.876420308 orig 9.895540064 orig 9.900466407 orig 9.851785308 orig 9.893819847 orig 9.875527071 orig 9.904952073 stll 9.738025396 stll 9.719086171 stll 10.183026952 stll 9.74686711 stll 9.719312983 stll 9.702301885 stll 9.735284114 stll 9.763578466 stll 9.721462461 stll 9.747227936 ----------------------------------------------------------- vm1_gc_short_with_symbol # make many symbols 50_000.times{|i| sym =3D "sym#{i}".to_sym} GC.start GC.start i =3D 0 while i<30_000_000 # while loop 1 a =3D '' # short-lived String b =3D '' c =3D '' d =3D '' e =3D '' f =3D '' i+=3D1 end orig 9.50395045 orig 9.584649781 orig 9.719530802 orig 9.594610927 orig 9.338013872 orig 9.403705508 orig 10.788435743 orig 9.423518406 orig 10.013764648 orig 9.570680255 stll 9.208967684 stll 9.382788648 stll 9.32592605 stll 9.214151825 stll 9.212628448 stll 9.275158815 stll 9.382481485 stll 9.387072921 stll 9.167268354 stll 9.494654659 ----------------------------------------------------------- vm1_gc_wb_ary long_lived =3D [] GC.start GC.start i =3D 0 short_lived =3D '' while i<30_000_000 # while loop 1 long_lived[0] =3D short_lived # write barrier i+=3D1 end orig 1.147797702 orig 1.07551601 orig 1.083096096 orig 1.074741102 orig 1.075512916 orig 1.087115413 orig 1.075316172 orig 1.077487324 orig 1.075465058 orig 1.075222562 stll 1.064514195 stll 1.065066605 stll 1.067178167 stll 1.06696848 stll 1.104947844 stll 1.0698162 stll 1.067390951 stll 1.065605883 stll 1.14866906 stll 1.085749239 ----------------------------------------------------------- vm1_gc_wb_obj class C attr_accessor :foo end long_lived =3D C.new GC.start GC.start i =3D 0 short_lived =3D '' while i<30_000_000 # while loop 1 long_lived.foo =3D short_lived # write barrier i+=3D1 end orig 1.065491155 orig 1.339934267 orig 1.126352377 orig 1.118274006 orig 1.121598522 orig 1.0945944 orig 1.299849679 orig 1.126306965 orig 1.051445321 orig 1.359615822 stll 1.529405906 stll 1.061978983 stll 1.059987439 stll 1.056625144 stll 1.061240029 stll 1.058547356 stll 1.064332586 stll 1.06430658 stll 1.284736673 stll 1.081213917 ----------------------------------------------------------- vm1_ivar @a =3D 1 i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 j =3D @a k =3D @a end orig 0.732845415 orig 0.736293149 orig 0.771818895 orig 0.840215944 orig 0.756953726 orig 0.73349172 orig 0.732729929 orig 0.732720846 orig 0.732638614 orig 0.733124223 stll 0.733305094 stll 0.73316103 stll 0.733085095 stll 0.73311374 stll 0.733009473 stll 0.740021408 stll 0.733247148 stll 0.733161471 stll 0.733154861 stll 0.733016812 ----------------------------------------------------------- vm1_ivar_set i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 @a =3D 1 @b =3D 2 end orig 0.906701623 orig 0.90271781 orig 0.891999967 orig 0.890021645 orig 0.897370889 orig 0.888535227 orig 0.956963337 orig 0.912073158 orig 1.346196183 orig 0.966576753 stll 1.12214036 stll 0.964292539 stll 1.021842033 stll 1.282939856 stll 1.159691711 stll 1.361047186 stll 0.922545639 stll 1.003385877 stll 1.263600194 stll 0.93657982 ----------------------------------------------------------- vm1_length a =3D 'abc' b =3D [1, 2, 3] i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 a.length b.length end orig 0.919564573 orig 0.923974728 orig 0.920407549 orig 0.920451743 orig 0.920319989 orig 0.920456607 orig 0.920767013 orig 0.920226718 orig 0.920368093 orig 0.920341266 stll 0.92076659 stll 0.920485496 stll 0.920565386 stll 1.26941394 stll 0.920474983 stll 0.92038875 stll 0.920444582 stll 0.9203879 stll 0.923340819 stll 0.921364909 ----------------------------------------------------------- vm1_lvar_init def m v unless v # unreachable code v1 =3D v2 =3D v3 =3D v4 =3D v5 =3D v6 =3D v7 =3D v8 =3D v9 =3D v10 =3D v11 =3D v12 =3D v13 =3D v14 =3D v15 =3D v16 =3D v17 =3D v18 =3D v19 =3D= v20 =3D v21 =3D v22 =3D v23 =3D v24 =3D v25 =3D v26 =3D v27 =3D v28 =3D v29 =3D= v30 =3D v31 =3D v32 =3D v33 =3D v34 =3D v35 =3D v36 =3D v37 =3D v38 =3D v39 =3D= v40 =3D v41 =3D v42 =3D v43 =3D v44 =3D v45 =3D v46 =3D v47 =3D v48 =3D v49 =3D= v50 =3D 1 end end i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 m i end orig 1.71203098 orig 1.708061695 orig 1.933030959 orig 1.814921006 orig 2.065309732 orig 1.733509022 orig 1.780352332 orig 2.16590027 orig 1.783162329 orig 2.626269635 stll 2.558632335 stll 1.861565075 stll 2.577726662 stll 2.631456942 stll 1.827923592 stll 1.702482632 stll 1.71663206 stll 1.754538343 stll 1.696627162 stll 1.691055796 ----------------------------------------------------------- vm1_lvar_set i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 a =3D b =3D c =3D d =3D e =3D f =3D g =3D h =3D j =3D k =3D l =3D m =3D n= =3D o =3D p =3D q =3D r =3D 1 end orig 2.475366347 orig 2.473178776 orig 2.476519503 orig 2.476033007 orig 2.475486809 orig 2.473323796 orig 2.517870031 orig 2.625114464 orig 2.484786033 orig 2.596214747 stll 2.526130626 stll 2.610164374 stll 2.88131717 stll 2.851746956 stll 2.762483063 stll 2.472280032 stll 2.472686528 stll 2.472592859 stll 2.47240747 stll 2.473508289 ----------------------------------------------------------- vm1_neq i =3D 0 obj1 =3D Object.new obj2 =3D Object.new while i<30_000_000 # while loop 1 i +=3D 1 obj1 !=3D obj2 end orig 0.968142968 orig 0.954512479 orig 0.955811063 orig 0.954303277 orig 1.058883621 orig 1.009745469 orig 0.990800628 orig 1.049664067 orig 1.161817696 orig 1.632842791 stll 1.121360525 stll 0.95798036 stll 0.9535098 stll 1.343705833 stll 0.975003782 stll 0.959950174 stll 1.339184229 stll 1.218822788 stll 0.959301719 stll 0.988312683 ----------------------------------------------------------- vm1_not i =3D 0 obj =3D Object.new while i<30_000_000 # while loop 1 i +=3D 1 !obj end orig 1.058006785 orig 0.894977125 orig 0.74971253 orig 0.999090716 orig 1.080774049 orig 0.980370634 orig 0.779352881 orig 0.748725214 orig 0.7492704 orig 0.791591259 stll 0.760867522 stll 0.817209155 stll 0.765411921 stll 0.750915306 stll 1.016355917 stll 0.803063321 stll 0.781027784 stll 0.898436709 stll 0.793891822 stll 0.785001297 ----------------------------------------------------------- vm1_rescue i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 begin rescue end end orig 0.614962557 orig 0.618616117 orig 0.627111337 orig 0.62586782 orig 0.754401771 orig 0.854392256 orig 0.686720247 orig 0.613991738 orig 0.613965382 orig 0.615000411 stll 0.616104035 stll 0.633980773 stll 0.625831908 stll 0.634039862 stll 0.614295319 stll 0.614046736 stll 0.613890434 stll 0.613880872 stll 0.613995646 stll 0.613880132 ----------------------------------------------------------- vm1_simplereturn def m return 1 end i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 m end orig 1.226309989 orig 1.387738832 orig 1.256992291 orig 1.24285113 orig 1.225559321 orig 1.223404655 orig 1.224599234 orig 1.226168386 orig 1.226112643 orig 1.225337169 stll 1.248849294 stll 1.225427281 stll 1.222688858 stll 1.222109651 stll 1.222273327 stll 1.221765554 stll 1.222243693 stll 1.370048617 stll 1.344156583 stll 1.226515337 ----------------------------------------------------------- vm1_swap a =3D 1 b =3D 2 i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 a, b =3D b, a end orig 0.730301752 orig 0.731396407 orig 0.83343086 orig 0.728030834 orig 0.89796579 orig 1.000808575 orig 0.999893291 orig 0.896495108 orig 0.730830802 orig 0.727731168 stll 0.727961825 stll 0.773433632 stll 0.743611846 stll 0.945669505 stll 0.944430407 stll 0.942770799 stll 0.943226399 stll 0.783553899 stll 0.726884758 stll 0.726973646 ----------------------------------------------------------- vm1_yield def m i =3D 0 while i<30_000_000 # while loop 1 i +=3D 1 yield end end m{} orig 1.17570019 orig 1.229845265 orig 1.400185349 orig 1.321732851 orig 1.258243122 orig 2.123445381 orig 1.724213478 orig 1.478238257 orig 1.205834779 orig 1.176394306 stll 1.228914764 stll 1.188647615 stll 1.19757616 stll 1.360537121 stll 1.180653906 stll 1.24975019 stll 1.3785968 stll 1.231586966 stll 1.234262815 stll 1.247705207 ----------------------------------------------------------- vm2_array i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 a =3D [1,2,3,4,5,6,7,8,9,10] end orig 0.73824619 orig 0.737371085 orig 0.807479761 orig 0.744885591 orig 0.747952004 orig 0.743777795 orig 0.736196617 orig 0.738309815 orig 0.737062439 orig 0.750747667 stll 0.771446239 stll 0.757887449 stll 0.738576221 stll 0.809367362 stll 0.755662815 stll 0.740865405 stll 0.745320753 stll 0.772665581 stll 0.7367682 stll 0.771393985 ----------------------------------------------------------- vm2_bigarray i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 a =3D [ 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,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.686484237 orig 6.708665217 orig 6.715444231 orig 6.728438973 orig 6.699407643 orig 6.773321832 orig 6.731451273 orig 6.768405943 orig 6.957647974 orig 6.8823709 stll 6.990485803 stll 6.85722822 stll 7.04176214 stll 7.059733317 stll 7.042386024 stll 6.891391669 stll 6.73829468 stll 7.213554228 stll 6.951761117 stll 6.957400362 ----------------------------------------------------------- vm2_bighash i =3D 0 while i<60_000 # benchmark loop 2 i +=3D 1 a =3D {0=3D>0, 1=3D>1, 2=3D>2, 3=3D>3, 4=3D>4, 5=3D>5, 6=3D>6, 7=3D>7, 8= =3D>8, 9=3D>9, 10=3D>10, 11=3D>11, 12=3D>12, 13=3D>13, 14=3D>14, 15=3D>15, = 16=3D>16, 17=3D>17, 18=3D>18, 19=3D>19, 20=3D>20, 21=3D>21, 22=3D>22, 23=3D= >23, 24=3D>24, 25=3D>25, 26=3D>26, 27=3D>27, 28=3D>28, 29=3D>29, 30=3D>30, = 31=3D>31, 32=3D>32, 33=3D>33, 34=3D>34, 35=3D>35, 36=3D>36, 37=3D>37, 38=3D= >38, 39=3D>39, 40=3D>40, 41=3D>41, 42=3D>42, 43=3D>43, 44=3D>44, 45=3D>45, = 46=3D>46, 47=3D>47, 48=3D>48, 49=3D>49, 50=3D>50, 51=3D>51, 52=3D>52, 53=3D= >53, 54=3D>54, 55=3D>55, 56=3D>56, 57=3D>57, 58=3D>58, 59=3D>59, 60=3D>60, = 61=3D>61, 62=3D>62, 63=3D>63, 64=3D>64, 65=3D>65, 66=3D>66, 67=3D>67, 68=3D= >68, 69=3D>69, 70=3D>70, 71=3D>71, 72=3D>72, 73=3D>73, 74=3D>74, 75=3D>75, = 76=3D>76, 77=3D>77, 78=3D>78, 79=3D>79, 80=3D>80, 81=3D>81, 82=3D>82, 83=3D= >83, 84=3D>84, 85=3D>85, 86=3D>86, 87=3D>87, 88=3D>88, 89=3D>89, 90=3D>90, = 91=3D>91, 92=3D>92, 93=3D>93, 94=3D>94, 95=3D>95, 96=3D>96, 97=3D>97, 98=3D= >98, 99=3D>99, 100=3D>100, 101=3D>101, 102=3D>102, 103=3D>103, 104=3D>104, = 105=3D>105, 106=3D>106, 107=3D>107, 108=3D>108, 109=3D>109, 110=3D>110, 111= =3D>111, 112=3D>112, 113=3D>113, 114=3D>114, 115=3D>115, 116=3D>116, 117=3D= >117, 118=3D>118, 119=3D>119, 120=3D>120, 121=3D>121, 122=3D>122, 123=3D>12= 3, 124=3D>124, 125=3D>125, 126=3D>126, 127=3D>127, 128=3D>128, 129=3D>129, = 130=3D>130, 131=3D>131, 132=3D>132, 133=3D>133, 134=3D>134, 135=3D>135, 136= =3D>136, 137=3D>137, 138=3D>138, 139=3D>139, 140=3D>140, 141=3D>141, 142=3D= >142, 143=3D>143, 144=3D>144, 145=3D>145, 146=3D>146, 147=3D>147, 148=3D>14= 8, 149=3D>149, 150=3D>150, 151=3D>151, 152=3D>152, 153=3D>153, 154=3D>154, = 155=3D>155, 156=3D>156, 157=3D>157, 158=3D>158, 159=3D>159, 160=3D>160, 161= =3D>161, 162=3D>162, 163=3D>163, 164=3D>164, 165=3D>165, 166=3D>166, 167=3D= >167, 168=3D>168, 169=3D>169, 170=3D>170, 171=3D>171, 172=3D>172, 173=3D>17= 3, 174=3D>174, 175=3D>175, 176=3D>176, 177=3D>177, 178=3D>178, 179=3D>179, = 180=3D>180, 181=3D>181, 182=3D>182, 183=3D>183, 184=3D>184, 185=3D>185, 186= =3D>186, 187=3D>187, 188=3D>188, 189=3D>189, 190=3D>190, 191=3D>191, 192=3D= >192, 193=3D>193, 194=3D>194, 195=3D>195, 196=3D>196, 197=3D>197, 198=3D>19= 8, 199=3D>199, 200=3D>200, 201=3D>201, 202=3D>202, 203=3D>203, 204=3D>204, = 205=3D>205, 206=3D>206, 207=3D>207, 208=3D>208, 209=3D>209, 210=3D>210, 211= =3D>211, 212=3D>212, 213=3D>213, 214=3D>214, 215=3D>215, 216=3D>216, 217=3D= >217, 218=3D>218, 219=3D>219, 220=3D>220, 221=3D>221, 222=3D>222, 223=3D>22= 3, 224=3D>224, 225=3D>225, 226=3D>226, 227=3D>227, 228=3D>228, 229=3D>229, = 230=3D>230, 231=3D>231, 232=3D>232, 233=3D>233, 234=3D>234, 235=3D>235, 236= =3D>236, 237=3D>237, 238=3D>238, 239=3D>239, 240=3D>240, 241=3D>241, 242=3D= >242, 243=3D>243, 244=3D>244, 245=3D>245, 246=3D>246, 247=3D>247, 248=3D>24= 8, 249=3D>249, 250=3D>250, 251=3D>251, 252=3D>252, 253=3D>253, 254=3D>254, = 255=3D>255, 256=3D>256, 257=3D>257, 258=3D>258, 259=3D>259, 260=3D>260, 261= =3D>261, 262=3D>262, 263=3D>263, 264=3D>264, 265=3D>265, 266=3D>266, 267=3D= >267, 268=3D>268, 269=3D>269, 270=3D>270, 271=3D>271, 272=3D>272, 273=3D>27= 3, 274=3D>274, 275=3D>275, 276=3D>276, 277=3D>277, 278=3D>278, 279=3D>279, = 280=3D>280, 281=3D>281, 282=3D>282, 283=3D>283, 284=3D>284, 285=3D>285, 286= =3D>286, 287=3D>287, 288=3D>288, 289=3D>289, 290=3D>290, 291=3D>291, 292=3D= >292, 293=3D>293, 294=3D>294, 295=3D>295, 296=3D>296, 297=3D>297, 298=3D>29= 8, 299=3D>299, 300=3D>300, 301=3D>301, 302=3D>302, 303=3D>303, 304=3D>304, = 305=3D>305, 306=3D>306, 307=3D>307, 308=3D>308, 309=3D>309, 310=3D>310, 311= =3D>311, 312=3D>312, 313=3D>313, 314=3D>314, 315=3D>315, 316=3D>316, 317=3D= >317, 318=3D>318, 319=3D>319, 320=3D>320, 321=3D>321, 322=3D>322, 323=3D>32= 3, 324=3D>324, 325=3D>325, 326=3D>326, 327=3D>327, 328=3D>328, 329=3D>329, = 330=3D>330, 331=3D>331, 332=3D>332, 333=3D>333, 334=3D>334, 335=3D>335, 336= =3D>336, 337=3D>337, 338=3D>338, 339=3D>339, 340=3D>340, 341=3D>341, 342=3D= >342, 343=3D>343, 344=3D>344, 345=3D>345, 346=3D>346, 347=3D>347, 348=3D>34= 8, 349=3D>349, 350=3D>350, 351=3D>351, 352=3D>352, 353=3D>353, 354=3D>354, = 355=3D>355, 356=3D>356, 357=3D>357, 358=3D>358, 359=3D>359, 360=3D>360, 361= =3D>361, 362=3D>362, 363=3D>363, 364=3D>364, 365=3D>365, 366=3D>366, 367=3D= >367, 368=3D>368, 369=3D>369, 370=3D>370, 371=3D>371, 372=3D>372, 373=3D>37= 3, 374=3D>374, 375=3D>375, 376=3D>376, 377=3D>377, 378=3D>378, 379=3D>379, = 380=3D>380, 381=3D>381, 382=3D>382, 383=3D>383, 384=3D>384, 385=3D>385, 386= =3D>386, 387=3D>387, 388=3D>388, 389=3D>389, 390=3D>390, 391=3D>391, 392=3D= >392, 393=3D>393, 394=3D>394, 395=3D>395, 396=3D>396, 397=3D>397, 398=3D>39= 8, 399=3D>399, 400=3D>400, 401=3D>401, 402=3D>402, 403=3D>403, 404=3D>404, = 405=3D>405, 406=3D>406, 407=3D>407, 408=3D>408, 409=3D>409, 410=3D>410, 411= =3D>411, 412=3D>412, 413=3D>413, 414=3D>414, 415=3D>415, 416=3D>416, 417=3D= >417, 418=3D>418, 419=3D>419, 420=3D>420, 421=3D>421, 422=3D>422, 423=3D>42= 3, 424=3D>424, 425=3D>425, 426=3D>426, 427=3D>427, 428=3D>428, 429=3D>429, = 430=3D>430, 431=3D>431, 432=3D>432, 433=3D>433, 434=3D>434, 435=3D>435, 436= =3D>436, 437=3D>437, 438=3D>438, 439=3D>439, 440=3D>440, 441=3D>441, 442=3D= >442, 443=3D>443, 444=3D>444, 445=3D>445, 446=3D>446, 447=3D>447, 448=3D>44= 8, 449=3D>449, 450=3D>450, 451=3D>451, 452=3D>452, 453=3D>453, 454=3D>454, = 455=3D>455, 456=3D>456, 457=3D>457, 458=3D>458, 459=3D>459, 460=3D>460, 461= =3D>461, 462=3D>462, 463=3D>463, 464=3D>464, 465=3D>465, 466=3D>466, 467=3D= >467, 468=3D>468, 469=3D>469, 470=3D>470, 471=3D>471, 472=3D>472, 473=3D>47= 3, 474=3D>474, 475=3D>475, 476=3D>476, 477=3D>477, 478=3D>478, 479=3D>479, = 480=3D>480, 481=3D>481, 482=3D>482, 483=3D>483, 484=3D>484, 485=3D>485, 486= =3D>486, 487=3D>487, 488=3D>488, 489=3D>489, 490=3D>490, 491=3D>491, 492=3D= >492, 493=3D>493, 494=3D>494, 495=3D>495, 496=3D>496, 497=3D>497, 498=3D>49= 8, 499=3D>499, 500=3D>500,} end orig 4.20879843 orig 3.910994204 orig 3.840111163 orig 3.840781478 orig 3.850745917 orig 3.878929864 orig 3.888859114 orig 3.832355612 orig 3.851203777 orig 3.805135264 stll 3.321646569 stll 3.357736691 stll 3.289268425 stll 3.348414717 stll 3.475979835 stll 3.494052154 stll 3.397488885 stll 3.36792594 stll 3.363455023 stll 3.312310045 ----------------------------------------------------------- vm2_case i =3D 0 while i<6_000_000 # while loop 2 case :foo when :bar raise when :baz raise when :boo raise when :foo i +=3D 1 end end orig 0.196835984 orig 0.195341766 orig 0.195162702 orig 0.194332785 orig 0.195400058 orig 0.198119613 orig 0.197866245 orig 0.198764721 orig 0.19691054 orig 0.194426193 stll 0.201035104 stll 0.195909645 stll 0.196587409 stll 0.197526548 stll 0.197254119 stll 0.197333349 stll 0.199120289 stll 0.207097861 stll 0.203300542 stll 0.197628782 ----------------------------------------------------------- vm2_defined_method class Object define_method(:m){} end i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 m; m; m; m; m; m; m; m; end orig 2.740640336 orig 2.716431221 orig 2.724859599 orig 2.933273936 orig 2.744307799 orig 2.961672792 orig 2.737026437 orig 2.728455237 orig 2.869693445 orig 2.996770567 stll 2.768419434 stll 3.020252934 stll 2.97175786 stll 3.021297248 stll 2.931910307 stll 3.07090447 stll 3.115585193 stll 3.166649582 stll 2.782318973 stll 3.001319958 ----------------------------------------------------------- vm2_dstr i =3D 0 x =3D y =3D 'z' while i<6_000_000 # benchmark loop 2 i +=3D 1 str =3D "foo#{x}bar#{y}baz" end orig 1.273185868 orig 1.267542551 orig 1.256862391 orig 1.256289059 orig 1.253628018 orig 1.255953478 orig 1.256287732 orig 1.275573216 orig 1.253663501 orig 1.253545566 stll 1.258879865 stll 1.259996063 stll 1.317688224 stll 1.314313777 stll 1.376796101 stll 1.261548187 stll 1.277180761 stll 1.382023106 stll 1.256838963 stll 1.259226783 ----------------------------------------------------------- vm2_eval i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 eval("1") end orig 13.490363308 orig 13.391284216 orig 13.319809015 orig 13.563180888 orig 13.459640705 orig 13.703297321 orig 13.490092353 orig 13.647006588 orig 13.314201223 orig 13.335290271 stll 13.489244819 stll 13.464344185 stll 13.386064361 stll 13.800102224 stll 13.449417796 stll 13.529014087 stll 13.403679597 stll 13.395622618 stll 13.531325513 stll 13.378471666 ----------------------------------------------------------- vm2_method def m nil end i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 m; m; m; m; m; m; m; m; end orig 1.497883019 orig 1.349596421 orig 1.383327376 orig 1.394124626 orig 1.359510367 orig 1.414043155 orig 1.36793866 orig 1.37444144 orig 1.372978551 orig 1.394028008 stll 1.391830038 stll 1.393725073 stll 1.363125867 stll 1.34614657 stll 1.38511985 stll 1.367251947 stll 1.351907635 stll 1.346439619 stll 1.371228239 stll 1.345467984 ----------------------------------------------------------- vm2_method_missing class C def method_missing mid end end obj =3D C.new i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; end orig 1.932546917 orig 1.934455679 orig 1.93854172 orig 1.950912021 orig 1.976581969 orig 1.942608988 orig 1.945635695 orig 1.949595676 orig 1.937782962 orig 1.940176255 stll 1.922861442 stll 1.979757776 stll 2.009199031 stll 2.084504719 stll 2.006731683 stll 2.170731467 stll 1.925568209 stll 1.933497754 stll 1.958627951 stll 2.023735618 ----------------------------------------------------------- vm2_method_with_block def m nil end i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 m{}; m{}; m{}; m{}; m{}; m{}; m{}; m{}; end orig 1.535500009 orig 1.534057029 orig 1.529463316 orig 1.532181882 orig 1.526631008 orig 1.526960027 orig 1.537940015 orig 1.550714434 orig 1.532147733 orig 1.525579625 stll 1.538325067 stll 1.521428564 stll 1.520290731 stll 1.539246577 stll 1.521422425 stll 1.528081874 stll 1.52097376 stll 1.518730775 stll 1.536835565 stll 1.572949428 ----------------------------------------------------------- vm2_mutex require 'thread' m =3D Mutex.new i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 m.synchronize{} end orig 0.739153718 orig 0.758694072 orig 0.72497689 orig 0.722191234 orig 0.773226641 orig 0.720953542 orig 0.7228843 orig 0.729210501 orig 0.767927142 orig 0.725675294 stll 0.727837451 stll 0.731015119 stll 0.725992194 stll 0.722904121 stll 0.723316265 stll 0.730713471 stll 0.727438374 stll 0.725525296 stll 0.724396052 stll 0.768241676 ----------------------------------------------------------- vm2_newlambda i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 lambda {} end orig 0.822555793 orig 0.832994932 orig 0.882269455 orig 0.820697696 orig 0.822728876 orig 0.821214081 orig 0.868972823 orig 0.870471792 orig 0.821473512 orig 0.821745978 stll 0.829513172 stll 0.873588178 stll 0.828993038 stll 0.824177145 stll 0.828011442 stll 0.824918656 stll 0.84767392 stll 0.826742896 stll 0.839770483 stll 0.843395494 ----------------------------------------------------------- vm2_poly_method class C1 def m 1 end end class C2 def m 2 end end o1 =3D C1.new o2 =3D C2.new i =3D 0 while i<6_000_000 # benchmark loop 2 o =3D (i % 2 =3D=3D 0) ? o1 : o2 o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i +=3D 1 end orig 2.326237859 orig 2.266256095 orig 2.235942037 orig 2.288210056 orig 2.274665021 orig 2.248117362 orig 2.258712091 orig 2.221985868 orig 2.23021852 orig 2.311983839 stll 2.223783136 stll 2.258611694 stll 2.257393307 stll 2.334440796 stll 2.557367006 stll 2.23185053 stll 2.237156024 stll 2.232835424 stll 2.239021717 stll 2.726531501 ----------------------------------------------------------- vm2_poly_method_ov class C1 def m 1 end end class C2 def m 2 end end o1 =3D C1.new o2 =3D C2.new i =3D 0 while i<6_000_000 # benchmark loop 2 o =3D (i % 2 =3D=3D 0) ? o1 : o2 # o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i +=3D 1 end orig 0.275886321 orig 0.305978652 orig 0.275437115 orig 0.275531912 orig 0.350827979 orig 0.293155119 orig 0.319846569 orig 0.302610138 orig 0.296192913 orig 0.301054013 stll 0.289516981 stll 0.274331768 stll 0.274466841 stll 0.273935342 stll 0.273578254 stll 0.2764675 stll 0.276368437 stll 0.2862352 stll 0.282155416 stll 0.286209383 ----------------------------------------------------------- vm2_proc def m &b b end pr =3D m{ a =3D 1 } i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 pr.call end orig 0.487605351 orig 0.492358452 orig 0.490108473 orig 0.496589868 orig 0.494560116 orig 0.532761958 orig 0.609371968 orig 0.498319369 orig 0.490103889 orig 0.735836153 stll 0.507268309 stll 0.493875729 stll 0.50110458 stll 0.525028376 stll 0.501418531 stll 0.498359718 stll 0.688990206 stll 0.505072285 stll 0.497818643 stll 0.54148073 ----------------------------------------------------------- vm2_raise1 def rec n if n > 0 rec n-1 else raise end end i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 begin rec 1 rescue # ignore end end orig 5.311127359 orig 5.390314221 orig 5.328343583 orig 5.562379409 orig 6.844047389 orig 5.57739729 orig 5.384502289 orig 5.73890192 orig 5.237066776 orig 5.615761964 stll 5.503445093 stll 5.225865177 stll 5.438818665 stll 5.64426263 stll 5.324782953 stll 5.381946793 stll 5.678803147 stll 5.310660225 stll 5.642545241 stll 5.345868388 ----------------------------------------------------------- vm2_raise2 def rec n if n > 0 rec n-1 else raise end end i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 begin rec 10 rescue # ignore end end orig 7.692413838 orig 7.696555486 orig 7.992847615 orig 7.810899032 orig 7.788691128 orig 8.124372478 orig 7.926554513 orig 7.738638769 orig 7.727894361 orig 7.775751114 stll 7.88410877 stll 7.776840742 stll 7.842858133 stll 7.724970863 stll 8.025117301 stll 7.785907733 stll 7.732682048 stll 7.812724216 stll 10.516519054 stll 8.221834305 ----------------------------------------------------------- vm2_regexp i =3D 0 str =3D 'xxxhogexxx' while i<6_000_000 # benchmark loop 2 /hoge/ =3D~ str i +=3D 1 end orig 1.268980275 orig 1.201561586 orig 1.28761712 orig 1.174532139 orig 1.176820961 orig 1.177446994 orig 1.191394707 orig 1.213051569 orig 1.229802049 orig 1.199717933 stll 1.406724093 stll 1.873657512 stll 1.235636588 stll 1.180592023 stll 1.180405011 stll 1.179492048 stll 1.179240929 stll 1.178992879 stll 1.179920336 stll 1.178143189 ----------------------------------------------------------- vm2_send class C def m end end o =3D C.new i =3D 0 while i<6_000_000 # benchmark loop 2 i +=3D 1 o.__send__ :m end orig 0.375499778 orig 0.375399703 orig 0.375428611 orig 0.375318016 orig 0.391465056 orig 0.375391269 orig 0.379284615 orig 0.375393927 orig 0.375227137 orig 0.375061281 stll 0.38743732 stll 0.37392435 stll 0.384839361 stll 0.374891749 stll 0.381980701 stll 0.399061969 stll 0.375260479 stll 0.424430882 stll 0.649389972 stll 0.658862578 ----------------------------------------------------------- vm2_super class C def m 1 end end class CC < C def m super() end end obj =3D CC.new i =3D 0 while i<6_000_000 # benchmark loop 2 obj.m i +=3D 1 end orig 0.958544917 orig 0.95822058 orig 0.819465865 orig 0.499026628 orig 0.499177863 orig 0.499600332 orig 0.500004225 orig 0.501529214 orig 0.500463355 orig 0.499805492 stll 0.507933667 stll 0.496059393 stll 0.516503062 stll 0.499936802 stll 0.504115618 stll 0.497044931 stll 0.525926702 stll 0.520227426 stll 0.497140025 stll 0.496479982 ----------------------------------------------------------- vm2_unif1 i =3D 0 def m a, b end while i<6_000_000 # benchmark loop 2 i +=3D 1 m 100, 200 end orig 0.276554421 orig 0.272975708 orig 0.272853563 orig 0.281795113 orig 0.27296358 orig 0.272952064 orig 0.275852591 orig 0.272725647 orig 0.272893154 orig 0.272895589 stll 0.27322529 stll 0.273127852 stll 0.273053935 stll 0.272907013 stll 0.273236757 stll 0.28468084 stll 0.315127313 stll 0.291731107 stll 0.286106583 stll 0.273239757 ----------------------------------------------------------- vm2_zsuper i =3D 0 class C def m a 1 end end class CC < C def m a super end end obj =3D CC.new while i<6_000_000 # benchmark loop 2 obj.m 10 i +=3D 1 end orig 0.514349501 orig 0.519724578 orig 0.516974954 orig 0.514313814 orig 0.515758378 orig 0.514475406 orig 0.827379433 orig 0.514494908 orig 0.526002028 orig 0.853725532 stll 0.51739732 stll 0.51495405 stll 0.546691061 stll 0.54049117 stll 0.644810826 stll 0.751828834 stll 0.588514948 stll 0.518992833 stll 0.512499102 stll 0.559811508 ----------------------------------------------------------- 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.144840928 orig 0.142657391 orig 0.142533026 orig 0.145085188 orig 0.142756092 orig 0.144094462 orig 0.146588816 orig 0.148375788 orig 0.140469535 orig 0.141194009 stll 0.141713494 stll 0.143726215 stll 0.141439089 stll 0.14475942 stll 0.144933465 stll 0.144800219 stll 0.143130206 stll 0.141121701 stll 0.141097222 stll 0.143603039 ----------------------------------------------------------- vm3_clearmethodcache i =3D 0 while i<200_000 i +=3D 1 Class.new{ def m; end } end orig 0.404271737 orig 0.39266564 orig 0.391837834 orig 0.391336176 orig 0.393378964 orig 0.395533111 orig 0.392877222 orig 0.400904708 orig 0.392621967 orig 0.390293488 stll 0.395890107 stll 0.413310319 stll 0.419650327 stll 0.399710606 stll 0.392865163 stll 0.39254773 stll 0.398473421 stll 0.39348053 stll 0.395670151 stll 0.392723628 ----------------------------------------------------------- vm3_gc #! /usr/bin/ruby 5000.times do 100.times do {"xxxx"=3D>"yyyy"} end GC.start end orig 2.115529024 orig 2.116169962 orig 2.140990368 orig 2.117888375 orig 2.107327782 orig 2.117847576 orig 2.107726879 orig 2.113756236 orig 2.098598614 orig 2.108233376 stll 2.236541119 stll 2.141630102 stll 2.106511716 stll 2.124389434 stll 2.112392234 stll 2.163199193 stll 2.186435535 stll 2.116584433 stll 2.112300412 stll 2.108126997 ----------------------------------------------------------- vm_thread_alive_check1 5_000.times{ t =3D Thread.new{} while t.alive? Thread.pass end } orig 40.654424318 orig 40.591822222 orig 40.703927842 orig 40.672611947 orig 40.630475949 orig 40.623682078 orig 40.581170949 orig 40.58866893 orig 40.600151628 orig 40.600728054 stll 40.587726318 stll 40.626521683 stll 40.671568378 stll 40.649703953 stll 40.666439782 stll 40.538390481 stll 40.662454896 stll 40.54273179 stll 40.494787422 stll 40.664949354 ----------------------------------------------------------- vm_thread_close 1000.times { Thread.new { sleep } } i =3D 0 while i<100_000 # benchmark loop 3 i +=3D 1 IO.pipe.each(&:close) end orig 3.450554812 orig 3.287614932 orig 3.252715753 orig 3.3008256 orig 3.381139325 orig 3.333134435 orig 3.250352337 orig 3.267024248 orig 3.238626588 orig 3.289960887 stll 3.266113851 stll 3.280930809 stll 3.366264585 stll 3.271376227 stll 3.264973628 stll 3.304123725 stll 3.173035934 stll 3.208949451 stll 3.326825231 stll 3.395628869 ----------------------------------------------------------- vm_thread_create_join i =3D 0 while i<100_000 # benchmark loop 3 i +=3D 1 Thread.new{ }.join end orig 2.372775092 orig 2.352637844 orig 2.262079765 orig 2.210738934 orig 2.205987859 orig 2.407110532 orig 2.173356132 orig 2.299178228 orig 2.229149612 orig 2.259245285 stll 2.224398723 stll 2.226041684 stll 2.300789101 stll 2.338296881 stll 2.296278624 stll 2.266404719 stll 2.452862553 stll 2.351395609 stll 2.283968555 stll 2.206752758 ----------------------------------------------------------- vm_thread_mutex1 # one thread, one mutex (no contention) require 'thread' m =3D Mutex.new r =3D 0 max =3D 2000 lmax =3D max * max (1..1).map{ Thread.new{ i =3D 0 while i