2014-08-21 16:50:26 +0900 target 0: 2_1 (ruby 2.1.2p205 (2014-08-21 revision 47229) [x86_64-linux]) at "ruby_2_1" target 1: 2_1_gc_patched (ruby 2.1.2p205 (2014-08-21 revision 47229) [x86_64-linux]) at "install/ruby_2_1_gc_patched/bin/ruby" target 2: 2_1a (ruby 2.1.2p205 (2014-08-21 revision 47229) [x86_64-linux]) at "ruby_2_1" ----------------------------------------------------------- app_answer def ack(m, n) if m == 0 then n + 1 elsif n == 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end def the_answer_to_life_the_universe_and_everything (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i end answer = the_answer_to_life_the_universe_and_everything 2_1 0.068955942 2_1 0.068132452 2_1 0.061019659 2_1 0.063139122 2_1 0.066751197 2_1_gc_patched 0.070280714 2_1_gc_patched 0.066619791 2_1_gc_patched 0.065241501 2_1_gc_patched 0.067633763 2_1_gc_patched 0.065985975 2_1a 0.065895568 2_1a 0.068604149 2_1a 0.068519601 2_1a 0.068501409 2_1a 0.065923991 ----------------------------------------------------------- app_aobench # AO rebder benchmark # Original program (C) Syoyo Fujita in Javascript (and other languages) # http://lucille.atso-net.jp/blog/?p=642 # http://lucille.atso-net.jp/blog/?p=711 # Ruby(yarv2llvm) version by Hideki Miura # IMAGE_WIDTH = 256 IMAGE_HEIGHT = 256 NSUBSAMPLES = 2 NAO_SAMPLES = 8 class Vec def initialize(x, y, z) @x = x @y = y @z = z end attr_accessor :x, :y, :z def vadd(b) Vec.new(@x + b.x, @y + b.y, @z + b.z) end def vsub(b) Vec.new(@x - b.x, @y - b.y, @z - b.z) end def vcross(b) Vec.new(@y * b.z - @z * b.y, @z * b.x - @x * b.z, @x * b.y - @y * b.x) end def vdot(b) @x * b.x + @y * b.y + @z * b.z end def vlength Math.sqrt(@x * @x + @y * @y + @z * @z) end def vnormalize len = vlength v = Vec.new(@x, @y, @z) if len > 1.0e-17 then v.x = v.x / len v.y = v.y / len v.z = v.z / len end v end end class Sphere def initialize(center, radius) @center = center @radius = radius end attr_reader :center, :radius def intersect(ray, isect) rs = ray.org.vsub(@center) b = rs.vdot(ray.dir) c = rs.vdot(rs) - (@radius * @radius) d = b * b - c if d > 0.0 then t = - b - Math.sqrt(d) if t > 0.0 and t < isect.t then isect.t = t isect.hit = true isect.pl = Vec.new(ray.org.x + ray.dir.x * t, ray.org.y + ray.dir.y * t, ray.org.z + ray.dir.z * t) n = isect.pl.vsub(@center) isect.n = n.vnormalize else 0.0 end end nil end end class Plane def initialize(p, n) @p = p @n = n end def intersect(ray, isect) d = -@p.vdot(@n) v = ray.dir.vdot(@n) v0 = v if v < 0.0 then v0 = -v end if v0 < 1.0e-17 then return end t = -(ray.org.vdot(@n) + d) / v if t > 0.0 and t < isect.t then isect.hit = true isect.t = t isect.n = @n isect.pl = Vec.new(ray.org.x + t * ray.dir.x, ray.org.y + t * ray.dir.y, ray.org.z + t * ray.dir.z) end nil end end class Ray def initialize(org, dir) @org = org @dir = dir end attr_accessor :org, :dir end class Isect def initialize @t = 10000000.0 @hit = false @pl = Vec.new(0.0, 0.0, 0.0) @n = Vec.new(0.0, 0.0, 0.0) end attr_accessor :t, :hit, :pl, :n end def clamp(f) i = f * 255.5 if i > 255.0 then i = 255.0 end if i < 0.0 then i = 0.0 end i.to_i end def otherBasis(basis, n) basis[2] = Vec.new(n.x, n.y, n.z) basis[1] = Vec.new(0.0, 0.0, 0.0) if n.x < 0.6 and n.x > -0.6 then basis[1].x = 1.0 elsif n.y < 0.6 and n.y > -0.6 then basis[1].y = 1.0 elsif n.z < 0.6 and n.z > -0.6 then basis[1].z = 1.0 else basis[1].x = 1.0 end basis[0] = basis[1].vcross(basis[2]) basis[0] = basis[0].vnormalize basis[1] = basis[2].vcross(basis[0]) basis[1] = basis[1].vnormalize end class Scene def initialize @spheres = Array.new @spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5) @spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5) @spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5) @plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0)) end def ambient_occlusion(isect) basis = Array.new otherBasis(basis, isect.n) ntheta = NAO_SAMPLES nphi = NAO_SAMPLES eps = 0.0001 occlusion = 0.0 p0 = Vec.new(isect.pl.x + eps * isect.n.x, isect.pl.y + eps * isect.n.y, isect.pl.z + eps * isect.n.z) nphi.times do |j| ntheta.times do |i| r = rand phi = 2.0 * 3.14159265 * rand x = Math.cos(phi) * Math.sqrt(1.0 - r) y = Math.sin(phi) * Math.sqrt(1.0 - r) z = Math.sqrt(r) rx = x * basis[0].x + y * basis[1].x + z * basis[2].x ry = x * basis[0].y + y * basis[1].y + z * basis[2].y rz = x * basis[0].z + y * basis[1].z + z * basis[2].z raydir = Vec.new(rx, ry, rz) ray = Ray.new(p0, raydir) occisect = Isect.new @spheres[0].intersect(ray, occisect) @spheres[1].intersect(ray, occisect) @spheres[2].intersect(ray, occisect) @plane.intersect(ray, occisect) if occisect.hit then occlusion = occlusion + 1.0 else 0.0 end end end occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f) Vec.new(occlusion, occlusion, occlusion) end def render(w, h, nsubsamples) cnt = 0 nsf = nsubsamples.to_f h.times do |y| w.times do |x| rad = Vec.new(0.0, 0.0, 0.0) # Subsmpling nsubsamples.times do |v| nsubsamples.times do |u| cnt = cnt + 1 wf = w.to_f hf = h.to_f xf = x.to_f yf = y.to_f uf = u.to_f vf = v.to_f px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0) py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0) eye = Vec.new(px, py, -1.0).vnormalize ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye) isect = Isect.new @spheres[0].intersect(ray, isect) @spheres[1].intersect(ray, isect) @spheres[2].intersect(ray, isect) @plane.intersect(ray, isect) if isect.hit then col = ambient_occlusion(isect) rad.x = rad.x + col.x rad.y = rad.y + col.y rad.z = rad.z + col.z end end end r = rad.x / (nsf * nsf) g = rad.y / (nsf * nsf) b = rad.z / (nsf * nsf) printf("%c", clamp(r)) printf("%c", clamp(g)) printf("%c", clamp(b)) end nil end nil end end alias printf_orig printf def printf *args end # File.open("ao.ppm", "w") do |fp| printf("P6\n") printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT) printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT) Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES) # end undef printf alias printf printf_orig 2_1 59.599552411 2_1 60.395882832 2_1 58.587874735 2_1 59.229732407 2_1 59.847442624 2_1_gc_patched 59.32816919 2_1_gc_patched 58.289985116 2_1_gc_patched 59.696445009 2_1_gc_patched 58.567247435 2_1_gc_patched 58.011991159 2_1a 59.414767458 2_1a 59.501531481 2_1a 59.421512916 2_1a 59.344681773 2_1a 59.00713581 ----------------------------------------------------------- app_erb # # Create many HTML strings with ERB. # require 'erb' data = DATA.read max = 15_000 title = "hello world!" content = "hello world!\n" * 10 max.times{ ERB.new(data).result(binding) } __END__ <%= title %>

<%= title %>

<%= content %>

2_1 1.252991886 2_1 1.233189464 2_1 1.241880731 2_1 1.245435461 2_1 1.22059591 2_1_gc_patched 1.24008176 2_1_gc_patched 1.230143087 2_1_gc_patched 1.236996892 2_1_gc_patched 1.249821106 2_1_gc_patched 1.239668064 2_1a 1.231087234 2_1a 1.243697455 2_1a 1.233823322 2_1a 1.253057197 2_1a 1.234510388 ----------------------------------------------------------- app_factorial def fact(n) if(n > 1) n * fact(n-1) else 1 end end 100.times { fact(5000) } 2_1 0.681743627 2_1 0.68107784 2_1 0.680900473 2_1 0.68110084 2_1 0.681186762 2_1_gc_patched 0.678103415 2_1_gc_patched 0.684847797 2_1_gc_patched 0.680311212 2_1_gc_patched 0.687127691 2_1_gc_patched 0.67824248 2_1a 0.690994286 2_1a 0.687280881 2_1a 0.68177449 2_1a 0.6803248 2_1a 0.684866734 ----------------------------------------------------------- app_fib def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(34) 2_1 0.567993739 2_1 0.527127879 2_1 0.62695402 2_1 0.575857807 2_1 0.631448071 2_1_gc_patched 0.522914196 2_1_gc_patched 0.640058178 2_1_gc_patched 0.616916371 2_1_gc_patched 0.6185107 2_1_gc_patched 0.618264139 2_1a 0.641394513 2_1a 0.634118087 2_1a 0.626521712 2_1a 0.634777066 2_1a 0.619462489 ----------------------------------------------------------- app_mandelbrot require 'complex' def mandelbrot? z i = 0 while i<100 i += 1 z = z * z return false if z.abs > 2 end true end ary = [] (0..1000).each{|dx| (0..1000).each{|dy| x = dx / 50.0 y = dy / 50.0 c = Complex(x, y) ary << c if mandelbrot?(c) } } 2_1 1.193504854 2_1 1.258208753 2_1 1.25617169 2_1 1.295605938 2_1 1.272433536 2_1_gc_patched 1.2673259 2_1_gc_patched 1.206065464 2_1_gc_patched 1.258485551 2_1_gc_patched 1.238491394 2_1_gc_patched 1.351553238 2_1a 1.300896554 2_1a 1.242578302 2_1a 1.187014848 2_1a 1.241987174 2_1a 1.251268833 ----------------------------------------------------------- app_pentomino #!/usr/local/bin/ruby # This program is contributed by Shin Nishiyama # modified by K.Sasada NP = 5 ROW = 8 + NP COL = 8 $p = [] $b = [] $no = 0 def piece(n, a, nb) nb.each{|x| a[n] = x if n == NP-1 $p << [a.sort] else nbc=nb.dup [-ROW, -1, 1, ROW].each{|d| if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d) nbc << x+d end } nbc.delete x piece(n+1,a[0..n],nbc) end } end def kikaku(a) a.collect {|x| x - a[0]} end def ud(a) kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) end def rl(a) kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) end def xy(a) kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) end def mkpieces piece(0,[],[0]) $p.each do |a| a0 = a[0] a[1] = ud(a0) a[2] = rl(a0) a[3] = ud(rl(a0)) a[4] = xy(a0) a[5] = ud(xy(a0)) a[6] = rl(xy(a0)) a[7] = ud(rl(xy(a0))) a.sort! a.uniq! end $p.uniq!.sort! {|x,y| x[0] <=> y[0] } end def mkboard (0...ROW*COL).each{|i| if i % ROW >= ROW-NP $b[i] = -2 else $b[i] = -1 end $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 } end def pboard return # skip print print "No. #$no\n" (0...COL).each{|i| print "|" (0...ROW-NP).each{|j| x = $b[i*ROW+j] if x < 0 print "..|" else printf "%2d|",x+1 end } print "\n" } print "\n" end $pnum=[] def setpiece(a,pos) if a.length == $p.length then $no += 1 pboard return end while $b[pos] != -1 pos += 1 end ($pnum - a).each do |i| $p[i].each do |x| f = 0 x.each{|s| if $b[pos+s] != -1 f=1 break end } if f == 0 then x.each{|s| $b[pos+s] = i } a << i setpiece(a.dup, pos) a.pop x.each{|s| $b[pos+s] = -1 } end end end end mkpieces mkboard $p[4] = [$p[4][0]] $pnum = (0...$p.length).to_a setpiece([],0) __END__ # original NP = 5 ROW = 8 + NP COL = 8 $p = [] $b = [] $no = 0 def piece(n,a,nb) for x in nb a[n] = x if n == NP-1 $p << [a.sort] else nbc=nb.dup for d in [-ROW, -1, 1, ROW] if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d) nbc << x+d end end nbc.delete x piece(n+1,a[0..n],nbc) end end end def kikaku(a) a.collect {|x| x - a[0]} end def ud(a) kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) end def rl(a) kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) end def xy(a) kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) end def mkpieces piece(0,[],[0]) $p.each do |a| a0 = a[0] a[1] = ud(a0) a[2] = rl(a0) a[3] = ud(rl(a0)) a[4] = xy(a0) a[5] = ud(xy(a0)) a[6] = rl(xy(a0)) a[7] = ud(rl(xy(a0))) a.sort! a.uniq! end $p.uniq!.sort! {|x,y| x[0] <=> y[0] } end def mkboard for i in 0...ROW*COL if i % ROW >= ROW-NP $b[i] = -2 else $b[i] = -1 end $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 end end def pboard print "No. #$no\n" for i in 0...COL print "|" for j in 0...ROW-NP x = $b[i*ROW+j] if x < 0 print "..|" else printf "%2d|",x+1 end end print "\n" end print "\n" end $pnum=[] def setpiece(a,pos) if a.length == $p.length then $no += 1 pboard return end while $b[pos] != -1 pos += 1 end ($pnum - a).each do |i| $p[i].each do |x| f = 0 for s in x do if $b[pos+s] != -1 f=1 break end end if f == 0 then for s in x do $b[pos+s] = i end a << i setpiece(a.dup, pos) a.pop for s in x do $b[pos+s] = -1 end end end end end mkpieces mkboard $p[4] = [$p[4][0]] $pnum = (0...$p.length).to_a setpiece([],0) 2_1 17.440887137 2_1 17.546119542 2_1 18.10003173 2_1 17.717904978 2_1 17.142817728 2_1_gc_patched 16.570893678 2_1_gc_patched 16.268319974 2_1_gc_patched 16.267258706 2_1_gc_patched 17.204974898 2_1_gc_patched 17.495156572 2_1a 17.696426618 2_1a 17.330858323 2_1a 17.837967706 2_1a 17.190103159 2_1a 18.279232977 ----------------------------------------------------------- app_raise i = 0 while i<300000 i += 1 begin raise rescue end end 2_1 0.357351139 2_1 0.353649072 2_1 0.386773158 2_1 0.372007406 2_1 0.364568708 2_1_gc_patched 0.351326874 2_1_gc_patched 0.354087419 2_1_gc_patched 0.369170936 2_1_gc_patched 0.405774896 2_1_gc_patched 0.354921256 2_1a 0.35137796 2_1a 0.356671524 2_1a 0.364079019 2_1a 0.371732039 2_1a 0.355469276 ----------------------------------------------------------- app_strconcat i = 0 while i<2_000_000 "#{1+1} #{1+1} #{1+1}" i += 1 end 2_1 1.148198136 2_1 1.148292102 2_1 1.169882515 2_1 1.147298303 2_1 1.148708052 2_1_gc_patched 1.135176896 2_1_gc_patched 1.135315922 2_1_gc_patched 1.16423078 2_1_gc_patched 1.166270943 2_1_gc_patched 1.211365498 2_1a 1.267950805 2_1a 1.153056704 2_1a 1.156076119 2_1a 1.173970177 2_1a 1.147039745 ----------------------------------------------------------- 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) 2_1 0.876306539 2_1 1.032224541 2_1 1.04566803 2_1 1.031679098 2_1 0.945484469 2_1_gc_patched 0.945787096 2_1_gc_patched 0.849480453 2_1_gc_patched 0.835413334 2_1_gc_patched 0.853041194 2_1_gc_patched 0.810653773 2_1a 0.926202421 2_1a 1.035961725 2_1a 0.938485658 2_1a 1.033656166 2_1a 1.033611976 ----------------------------------------------------------- app_tarai def tarai( x, y, z ) if x <= y then y else tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y)) end end tarai(12, 6, 0) 2_1 0.756400925 2_1 0.667991803 2_1 0.662622648 2_1 0.755992414 2_1 0.763124435 2_1_gc_patched 0.603434468 2_1_gc_patched 0.603221188 2_1_gc_patched 0.598258498 2_1_gc_patched 0.639393071 2_1_gc_patched 0.734378768 2_1a 0.666630569 2_1a 0.763146891 2_1a 0.766522909 2_1a 0.76673452 2_1a 0.77197043 ----------------------------------------------------------- app_uri require 'uri' 100_000.times{ uri = URI.parse('http://www.ruby-lang.org') uri.scheme uri.host uri.port } 2_1 0.933802495 2_1 0.944716384 2_1 0.936636858 2_1 0.939745644 2_1 0.948321709 2_1_gc_patched 0.949898579 2_1_gc_patched 0.95603676 2_1_gc_patched 0.94047139 2_1_gc_patched 0.937810615 2_1_gc_patched 0.93299445 2_1a 0.955585455 2_1a 0.969707454 2_1a 0.946100538 2_1a 0.965225031 2_1a 0.945908683 ----------------------------------------------------------- hash_aref_miss h = {} strs = ('a'..'z').to_a.map!(&:freeze) strs.each { |s| h[s] = s } strs = ('A'..'Z').to_a 200_000.times { strs.each { |s| h[s] } } 2_1 0.544507984 2_1 0.543697491 2_1 0.619313884 2_1 0.570017907 2_1 0.555551054 2_1_gc_patched 0.522358782 2_1_gc_patched 0.560401431 2_1_gc_patched 0.536501535 2_1_gc_patched 0.54318095 2_1_gc_patched 0.547267948 2_1a 0.561617339 2_1a 0.548864001 2_1a 0.542790572 2_1a 0.555348236 2_1a 0.558623809 ----------------------------------------------------------- hash_aref_str h = {} strs = ('a'..'z').to_a.map!(&:freeze) strs.each { |s| h[s] = s } 200_000.times { strs.each { |s| h[s] } } 2_1 0.565123983 2_1 0.491456407 2_1 0.508669197 2_1 0.498062257 2_1 0.507100989 2_1_gc_patched 0.576631838 2_1_gc_patched 0.50261936 2_1_gc_patched 0.495487927 2_1_gc_patched 0.492289833 2_1_gc_patched 0.514572274 2_1a 0.500530468 2_1a 0.499298597 2_1a 0.503452031 2_1a 0.495393473 2_1a 0.494507942 ----------------------------------------------------------- hash_aref_sym h = {} syms = ('a'..'z').to_a.map(&:to_sym) syms.each { |s| h[s] = s } 200_000.times { syms.each { |s| h[s] } } 2_1 0.423063658 2_1 0.40896117 2_1 0.425008362 2_1 0.407735301 2_1 0.419429019 2_1_gc_patched 0.435814973 2_1_gc_patched 0.420493532 2_1_gc_patched 0.436950495 2_1_gc_patched 0.415401093 2_1_gc_patched 0.410902395 2_1a 0.413466359 2_1a 0.413606651 2_1a 0.411017072 2_1a 0.400883569 2_1a 0.402617212 ----------------------------------------------------------- hash_aref_sym_long h = {} syms = %w[puts warn syswrite write stat bacon lettuce tomato some symbols in this array may already be interned others should not be hash browns make good breakfast but not cooked using prime numbers shift for division entries delete_if keys exist? ].map!(&:to_sym) syms.each { |s| h[s] = s } 200_000.times { syms.each { |s| h[s] } } 2_1 0.617848121 2_1 0.60638137 2_1 0.61042201 2_1 0.614598502 2_1 0.714017493 2_1_gc_patched 0.612541595 2_1_gc_patched 0.632494397 2_1_gc_patched 0.623359877 2_1_gc_patched 0.639693665 2_1_gc_patched 0.624635887 2_1a 0.618736522 2_1a 0.621648233 2_1a 0.617746218 2_1a 0.617048406 2_1a 0.699247671 ----------------------------------------------------------- hash_flatten h = {} 10000.times do |i| h[i] = nil end 1000.times do h.flatten end 2_1 0.578634675 2_1 0.576473271 2_1 0.581186454 2_1 0.581414277 2_1 0.577747286 2_1_gc_patched 0.585980201 2_1_gc_patched 0.587875332 2_1_gc_patched 0.581873723 2_1_gc_patched 0.583902324 2_1_gc_patched 0.584949944 2_1a 0.579988456 2_1a 0.576958629 2_1a 0.575622914 2_1a 0.579679942 2_1a 0.579017669 ----------------------------------------------------------- hash_ident_num h = {}.compare_by_identity nums = (1..26).to_a nums.each { |n| h[n] = n } 200_000.times { nums.each { |n| h[n] } } 2_1 0.34722678 2_1 0.34201924 2_1 0.345144149 2_1 0.341914908 2_1 0.347237328 2_1_gc_patched 0.346209939 2_1_gc_patched 0.345790555 2_1_gc_patched 0.345433519 2_1_gc_patched 0.344391523 2_1_gc_patched 0.345555594 2_1a 0.342524703 2_1a 0.340922578 2_1a 0.346113656 2_1a 0.349464921 2_1a 0.3474357 ----------------------------------------------------------- hash_ident_obj h = {}.compare_by_identity objs = 26.times.map { Object.new } objs.each { |o| h[o] = o } 200_000.times { objs.each { |o| h[o] } } 2_1 0.342311623 2_1 0.342997446 2_1 0.339757522 2_1 0.347254144 2_1 0.34812882 2_1_gc_patched 0.355249103 2_1_gc_patched 0.407124366 2_1_gc_patched 0.344678994 2_1_gc_patched 0.34934555 2_1_gc_patched 0.371957468 2_1a 0.341820238 2_1a 0.342093677 2_1a 0.341654332 2_1a 0.352596188 2_1a 0.347962075 ----------------------------------------------------------- hash_ident_str h = {}.compare_by_identity strs = ('a'..'z').to_a strs.each { |s| h[s] = s } 200_000.times { strs.each { |s| h[s] } } 2_1 0.344688762 2_1 0.342476472 2_1 0.341436505 2_1 0.340809606 2_1 0.341029717 2_1_gc_patched 0.344533508 2_1_gc_patched 0.345331001 2_1_gc_patched 0.344495387 2_1_gc_patched 0.346224024 2_1_gc_patched 0.346541157 2_1a 0.342952352 2_1a 0.344792274 2_1a 0.345254417 2_1a 0.346879843 2_1a 0.345209549 ----------------------------------------------------------- hash_ident_sym h = {}.compare_by_identity syms = ('a'..'z').to_a.map(&:to_sym) syms.each { |s| h[s] = s } 200_000.times { syms.each { |s| h[s] } } 2_1 0.371244907 2_1 0.369245569 2_1 0.369997419 2_1 0.368313872 2_1 0.371153163 2_1_gc_patched 0.371498607 2_1_gc_patched 0.372012847 2_1_gc_patched 0.37176615 2_1_gc_patched 0.370505728 2_1_gc_patched 0.371320463 2_1a 0.372877349 2_1a 0.372770027 2_1a 0.368869843 2_1a 0.373177222 2_1a 0.369972008 ----------------------------------------------------------- hash_keys h = {} 10000.times do |i| h[i] = nil end 5000.times do h.keys end 2_1 0.226631207 2_1 0.22456032 2_1 0.227851311 2_1 0.231543151 2_1 0.23210016 2_1_gc_patched 0.225045034 2_1_gc_patched 0.224894953 2_1_gc_patched 0.226890069 2_1_gc_patched 0.224573649 2_1_gc_patched 0.224896083 2_1a 0.228365528 2_1a 0.223700842 2_1a 0.226773457 2_1a 0.228472422 2_1a 0.226857588 ----------------------------------------------------------- hash_shift h = {} 10000.times do |i| h[i] = nil end 50000.times do k, v = h.shift h[k] = v end 2_1 0.0422065 2_1 0.043172135 2_1 0.045890835 2_1 0.042150197 2_1 0.042667536 2_1_gc_patched 0.042492662 2_1_gc_patched 0.040522596 2_1_gc_patched 0.043021845 2_1_gc_patched 0.046586826 2_1_gc_patched 0.040576117 2_1a 0.042656935 2_1a 0.043191136 2_1a 0.042126153 2_1a 0.042214442 2_1a 0.041567755 ----------------------------------------------------------- hash_values h = {} 10000.times do |i| h[i] = nil end 5000.times do h.values end 2_1 0.232573806 2_1 0.236658463 2_1 0.238556032 2_1 0.232634349 2_1 0.231272299 2_1_gc_patched 0.233046383 2_1_gc_patched 0.229430005 2_1_gc_patched 0.230275995 2_1_gc_patched 0.230003116 2_1_gc_patched 0.230472895 2_1a 0.230475488 2_1a 0.231250156 2_1a 0.233605233 2_1a 0.234510085 2_1a 0.239584985 ----------------------------------------------------------- io_file_create # # Create files # max = 200_000 file = './tmpfile_of_bm_io_file_create' max.times{ f = open(file, 'w') f.close#(true) } File.unlink(file) 2_1 1.291275121 2_1 1.323553739 2_1 1.30196399 2_1 1.284146675 2_1 1.290700473 2_1_gc_patched 1.31554682 2_1_gc_patched 1.368933978 2_1_gc_patched 1.297270229 2_1_gc_patched 1.307972786 2_1_gc_patched 1.308235873 2_1a 1.298856223 2_1a 1.33778287 2_1a 1.286871563 2_1a 1.30199616 2_1a 1.325813574 ----------------------------------------------------------- io_file_read # # Seek and Read file. # require 'tempfile' max = 200_000 str = "Hello world! " * 1000 f = Tempfile.new('yarv-benchmark') f.write str max.times{ f.seek 0 f.read } 2_1 2.517757322 2_1 2.524952699 2_1 2.55533963 2_1 2.601221099 2_1 2.306726943 2_1_gc_patched 2.713986997 2_1_gc_patched 2.575660467 2_1_gc_patched 2.63152969 2_1_gc_patched 2.467336991 2_1_gc_patched 2.585636353 2_1a 2.564264356 2_1a 2.529895593 2_1a 2.608740797 2_1a 2.292551186 2_1a 2.299560799 ----------------------------------------------------------- io_file_write # # Seek and Write file. # require 'tempfile' max = 200_000 str = "Hello world! " * 1000 f = Tempfile.new('yarv-benchmark') max.times{ f.seek 0 f.write str } 2_1 0.919726244 2_1 0.943896317 2_1 0.940161296 2_1 0.932458104 2_1 0.967043136 2_1_gc_patched 1.015197463 2_1_gc_patched 0.919766621 2_1_gc_patched 0.914109844 2_1_gc_patched 0.944938951 2_1_gc_patched 0.923404582 2_1a 0.92052204 2_1a 0.945608295 2_1a 0.936955667 2_1a 0.95337726 2_1a 0.949395107 ----------------------------------------------------------- io_select # IO.select performance w = [ IO.pipe[1] ]; nr = 1000000 nr.times { IO.select nil, w } 2_1 1.510110842 2_1 1.471756765 2_1 1.497369456 2_1 1.542329201 2_1 1.531196053 2_1_gc_patched 1.470566042 2_1_gc_patched 1.459395726 2_1_gc_patched 1.462101476 2_1_gc_patched 1.44973988 2_1_gc_patched 1.484114783 2_1a 1.47719664 2_1a 1.522251408 2_1a 1.527574967 2_1a 1.481034895 2_1a 1.520793506 ----------------------------------------------------------- io_select2 # IO.select performance. worst case of single fd. ios = [] nr = 1000000 if defined?(Process::RLIMIT_NOFILE) max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] else max = 64 end puts "max fd: #{max} (results not apparent with <= 1024 max fd)" ((max / 2) - 10).times do ios.concat IO.pipe end last = [ ios[-1] ] puts "last IO: #{last[0].inspect}" nr.times do IO.select nil, last end 2_1 1.70479785 2_1 1.698564197 2_1 1.766489851 2_1 1.763484443 2_1 1.718899629 2_1_gc_patched 1.651072183 2_1_gc_patched 1.660569679 2_1_gc_patched 1.704169154 2_1_gc_patched 1.67703073 2_1_gc_patched 1.895735823 2_1a 1.662573304 2_1a 1.73744905 2_1a 1.76190404 2_1a 1.748531157 2_1a 1.756563022 ----------------------------------------------------------- io_select3 # IO.select performance. a lot of fd ios = [] nr = 100 if defined?(Process::RLIMIT_NOFILE) max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] else max = 64 end puts "max fd: #{max} (results not apparent with <= 1024 max fd)" (max - 10).times do r, w = IO.pipe r.close ios.push w end nr.times do IO.select nil, ios end 2_1 0.041800731 2_1 0.042020458 2_1 0.042435316 2_1 0.042197438 2_1 0.041980789 2_1_gc_patched 0.041703643 2_1_gc_patched 0.041581288 2_1_gc_patched 0.041378334 2_1_gc_patched 0.042374146 2_1_gc_patched 0.041369059 2_1a 0.042551047 2_1a 0.041553211 2_1a 0.042239149 2_1a 0.042149265 2_1a 0.041645207 ----------------------------------------------------------- loop_for for i in 1..30_000_000 # end 2_1 1.190653743 2_1 1.195894858 2_1 1.19232455 2_1 1.192720547 2_1 1.590990242 2_1_gc_patched 1.19475542 2_1_gc_patched 1.194866509 2_1_gc_patched 1.195069321 2_1_gc_patched 1.198101301 2_1_gc_patched 1.19818809 2_1a 1.19401621 2_1a 1.191380382 2_1a 1.19077862 2_1a 1.193531318 2_1a 1.194040818 ----------------------------------------------------------- loop_generator max = 600000 if defined? Fiber gen = (1..max).each loop do gen.next end else require 'generator' gen = Generator.new((0..max)) while gen.next? gen.next end end 2_1 0.750471423 2_1 0.69584523 2_1 0.729505087 2_1 0.73175968 2_1 0.697491805 2_1_gc_patched 0.701546075 2_1_gc_patched 0.726536569 2_1_gc_patched 0.700452827 2_1_gc_patched 0.699431184 2_1_gc_patched 0.70165305 2_1a 0.698167 2_1a 0.699478688 2_1a 0.731272016 2_1a 0.698595421 2_1a 0.706028964 ----------------------------------------------------------- loop_times 30_000_000.times{|e|} 2_1 1.131404441 2_1 1.134309419 2_1 1.127450416 2_1 1.129131105 2_1 1.129502652 2_1_gc_patched 1.12274004 2_1_gc_patched 1.12570499 2_1_gc_patched 1.125505607 2_1_gc_patched 1.126640887 2_1_gc_patched 1.123410537 2_1a 1.130442685 2_1a 1.132240741 2_1a 1.128890429 2_1a 1.132577417 2_1a 1.128056226 ----------------------------------------------------------- loop_whileloop i = 0 while i<30_000_000 # benchmark loop 1 i += 1 end 2_1 0.503810858 2_1 0.503658103 2_1 0.504023649 2_1 0.508879009 2_1 0.503326009 2_1_gc_patched 0.510609767 2_1_gc_patched 0.502726612 2_1_gc_patched 0.50676477 2_1_gc_patched 0.50301366 2_1_gc_patched 0.504312288 2_1a 0.50545565 2_1a 0.505716737 2_1a 0.505681886 2_1a 0.505357356 2_1a 0.504805671 ----------------------------------------------------------- loop_whileloop2 i = 0 while i< 6_000_000 # benchmark loop 2 i += 1 end 2_1 0.125444325 2_1 0.119142235 2_1 0.118883996 2_1 0.123737794 2_1 0.121406269 2_1_gc_patched 0.120828149 2_1_gc_patched 0.119154609 2_1_gc_patched 0.120083109 2_1_gc_patched 0.119491295 2_1_gc_patched 0.120593005 2_1a 0.119729414 2_1a 0.119487962 2_1a 0.119270447 2_1a 0.119347161 2_1a 0.118915325 ----------------------------------------------------------- securerandom require "securerandom" 20_0000.times do SecureRandom.random_number(100) end 2_1 1.101803655 2_1 1.151203456 2_1 1.087059846 2_1 1.09212636 2_1 1.080490537 2_1_gc_patched 1.179199085 2_1_gc_patched 1.063570903 2_1_gc_patched 1.063082261 2_1_gc_patched 1.057995698 2_1_gc_patched 1.064730184 2_1a 1.122273895 2_1a 1.106934824 2_1a 1.104734777 2_1a 1.110943105 2_1a 1.10239728 ----------------------------------------------------------- so_ackermann #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ def ack(m, n) if m == 0 then n + 1 elsif n == 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end NUM = 9 ack(3, NUM) 2_1 0.695326745 2_1 0.658913943 2_1 0.587508879 2_1 0.699836625 2_1 0.698654214 2_1_gc_patched 0.686049359 2_1_gc_patched 0.687985689 2_1_gc_patched 0.626482691 2_1_gc_patched 0.696139527 2_1_gc_patched 0.702308647 2_1a 0.593447959 2_1a 0.700588426 2_1a 0.655685973 2_1a 0.644952887 2_1a 0.594832327 ----------------------------------------------------------- so_array #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Paul Brannan and Mark Hubbart n = 9000 # Integer(ARGV.shift || 1) x = Array.new(n) y = Array.new(n, 0) n.times{|bi| x[bi] = bi + 1 } (0 .. 999).each do |e| (n-1).step(0,-1) do |bi| y[bi] += x.at(bi) end end # puts "#{y.first} #{y.last}" 2_1 0.970379674 2_1 1.050051026 2_1 1.058007885 2_1 0.950212385 2_1 0.962030757 2_1_gc_patched 0.867458514 2_1_gc_patched 0.865685209 2_1_gc_patched 0.877299231 2_1_gc_patched 0.876002579 2_1_gc_patched 0.868523812 2_1a 0.963021329 2_1a 1.102551316 2_1a 0.958340653 2_1a 0.972698339 2_1a 0.962686262 ----------------------------------------------------------- so_binary_trees # The Computer Language Shootout Benchmarks # http://shootout.alioth.debian.org # # contributed by Jesse Millikan # disable output alias puts_orig puts def puts str # disable puts end def item_check(tree) if tree[0] == nil tree[1] else tree[1] + item_check(tree[0]) - item_check(tree[2]) end end def bottom_up_tree(item, depth) if depth > 0 item_item = 2 * item depth -= 1 [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)] else [nil, item, nil] end end max_depth = 16 # ARGV[0].to_i min_depth = 4 max_depth = min_depth + 2 if min_depth + 2 > max_depth stretch_depth = max_depth + 1 stretch_tree = bottom_up_tree(0, stretch_depth) puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}" stretch_tree = nil long_lived_tree = bottom_up_tree(0, max_depth) min_depth.step(max_depth + 1, 2) do |depth| iterations = 2**(max_depth - depth + min_depth) check = 0 for i in 1..iterations temp_tree = bottom_up_tree(i, depth) check += item_check(temp_tree) temp_tree = bottom_up_tree(-i, depth) check += item_check(temp_tree) end puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}" end puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}" undef puts alias puts puts_orig 2_1 7.054346117 2_1 7.232056393 2_1 6.974983533 2_1 7.030388909 2_1 7.142621164 2_1_gc_patched 7.811081266 2_1_gc_patched 7.47831352 2_1_gc_patched 7.332557272 2_1_gc_patched 7.327661456 2_1_gc_patched 7.748555384 2_1a 7.035946765 2_1a 7.008515976 2_1a 7.382951542 2_1a 7.121083391 2_1a 7.074846169 ----------------------------------------------------------- so_concatenate #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # based on code from Aristarkh A Zagorodnikov and Dat Nguyen STUFF = "hello\n" i = 0 while i<10 i += 1 hello = '' 4_000_000.times do |e| hello << STUFF end end # puts hello.length 2_1 4.445793943 2_1 4.455237935 2_1 4.442694735 2_1 4.445502966 2_1 4.435746758 2_1_gc_patched 4.430387377 2_1_gc_patched 4.442925657 2_1_gc_patched 4.439389281 2_1_gc_patched 4.46954161 2_1_gc_patched 4.430847944 2_1a 4.445718632 2_1a 4.459370031 2_1a 4.443732777 2_1a 4.943287507 2_1a 4.441088261 ----------------------------------------------------------- so_count_words #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: wc-ruby.code,v 1.4 2004/11/13 07:43:32 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Paul Brannan input = open(File.join(File.dirname($0), 'wc.input'), 'rb') nl = nw = nc = 0 while true tmp = input.read(4096) or break data = tmp << (input.gets || "") nc += data.length nl += data.count("\n") ((data.strip! || data).tr!("\n", " ") || data).squeeze! nw += data.count(" ") + 1 end # STDERR.puts "#{nl} #{nw} #{nc}" 2_1 0.204973681 2_1 0.203917169 2_1 0.204176239 2_1 0.205563121 2_1 0.205245832 2_1_gc_patched 0.204280362 2_1_gc_patched 0.20417058 2_1_gc_patched 0.203624804 2_1_gc_patched 0.202267121 2_1_gc_patched 0.204546235 2_1a 0.203498735 2_1a 0.204631305 2_1a 0.204054295 2_1a 0.204600945 2_1a 0.210209229 ----------------------------------------------------------- so_exception #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ $HI = 0 $LO = 0 NUM = 250000 # Integer(ARGV[0] || 1) class Lo_Exception < Exception def initialize(num) @value = num end end class Hi_Exception < Exception def initialize(num) @value = num end end def some_function(num) begin hi_function(num) rescue print "We shouldn't get here, exception is: #{$!.type}\n" end end def hi_function(num) begin lo_function(num) rescue Hi_Exception $HI = $HI + 1 end end def lo_function(num) begin blowup(num) rescue Lo_Exception $LO = $LO + 1 end end def blowup(num) if num % 2 == 0 raise Lo_Exception.new(num) else raise Hi_Exception.new(num) end end i = 1 max = NUM+1 while i < max i += 1 some_function(i+1) end 2_1 0.372146984 2_1 0.375615355 2_1 0.371588629 2_1 0.381143709 2_1 0.386294072 2_1_gc_patched 0.404888662 2_1_gc_patched 0.417803579 2_1_gc_patched 0.408416273 2_1_gc_patched 0.422335334 2_1_gc_patched 0.386810021 2_1a 0.381124353 2_1a 0.379487579 2_1a 0.396854933 2_1a 0.355438143 2_1a 0.398732588 ----------------------------------------------------------- so_fannkuch # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura # Modified by Ryan Williams def fannkuch(n) maxFlips, m, r, check = 0, n-1, n, 0 count = (1..n).to_a perm = (1..n).to_a while true if check < 30 puts "#{perm}" check += 1 end while r != 1 count[r-1] = r r -= 1 end if perm[0] != 1 and perm[m] != n perml = perm.clone #.dup flips = 0 while (k = perml.first ) != 1 perml = perml.slice!(0, k).reverse + perml flips += 1 end maxFlips = flips if flips > maxFlips end while true if r==n then return maxFlips end perm.insert r,perm.shift break if (count[r] -= 1) > 0 r += 1 end end end def puts *args end N = 9 # (ARGV[0] || 1).to_i puts "Pfannkuchen(#{N}) = #{fannkuch(N)}" 2_1 1.227784838 2_1 1.227065688 2_1 1.232522851 2_1 1.246215718 2_1 1.226033546 2_1_gc_patched 1.28983082 2_1_gc_patched 1.223009785 2_1_gc_patched 1.240697363 2_1_gc_patched 1.198031251 2_1_gc_patched 1.243594688 2_1a 1.212972826 2_1a 1.221594786 2_1a 1.193283456 2_1a 1.22247423 2_1a 1.21176239 ----------------------------------------------------------- so_fasta # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura $last = 42.0 def gen_random (max,im=139968,ia=3877,ic=29573) (max * ($last = ($last * ia + ic) % im)) / im end alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" iub = [ ["a", 0.27], ["c", 0.12], ["g", 0.12], ["t", 0.27], ["B", 0.02], ["D", 0.02], ["H", 0.02], ["K", 0.02], ["M", 0.02], ["N", 0.02], ["R", 0.02], ["S", 0.02], ["V", 0.02], ["W", 0.02], ["Y", 0.02], ] homosapiens = [ ["a", 0.3029549426680], ["c", 0.1979883004921], ["g", 0.1975473066391], ["t", 0.3015094502008], ] def make_repeat_fasta(id, desc, src, n) puts ">#{id} #{desc}" v = nil width = 60 l = src.length s = src * ((n / l) + 1) s.slice!(n, l) puts(s.scan(/.{1,#{width}}/).join("\n")) end def make_random_fasta(id, desc, table, n) puts ">#{id} #{desc}" rand, v = nil,nil width = 60 chunk = 1 * width prob = 0.0 table.each{|v| v[1]= (prob += v[1])} for i in 1..(n/width) puts((1..width).collect{ rand = gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end if n%width != 0 puts((1..(n%width)).collect{ rand = gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end end n = (ARGV[0] or 250_000).to_i make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2) make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3) make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5) 2_1 2.017330941 2_1 2.010684364 2_1 2.084664744 2_1 2.000888368 2_1 2.003254031 2_1_gc_patched 2.136021864 2_1_gc_patched 2.10823993 2_1_gc_patched 2.233385085 2_1_gc_patched 1.962435467 2_1_gc_patched 2.159978143 2_1a 1.960025845 2_1a 1.924460179 2_1a 2.023021016 2_1a 2.186232341 2_1a 2.02510223 ----------------------------------------------------------- so_k_nucleotide # The Computer Language Shootout # http://shootout.alioth.debian.org # # contributed by jose fco. gonzalez # modified by Sokolov Yura seq = String.new def frecuency( seq,length ) n, table = seq.length - length + 1, Hash.new(0) f, i = nil, nil (0 ... length).each do |f| (f ... n).step(length) do |i| table[seq[i,length]] += 1 end end [n,table] end def sort_by_freq( seq,length ) n,table = frecuency( seq,length ) a, b, v = nil, nil, nil table.sort{|a,b| b[1] <=> a[1]}.each do |v| puts "%s %.3f" % [v[0].upcase,((v[1]*100).to_f/n)] end puts end def find_seq( seq,s ) n,table = frecuency( seq,s.length ) puts "#{table[s].to_s}\t#{s.upcase}" end input = open(File.join(File.dirname($0), 'fasta.output.100000'), 'rb') line = input.gets while line !~ /^>THREE/ line = input.gets while (line !~ /^>/) & line do seq << line.chomp line = input.gets end [1,2].each {|i| sort_by_freq( seq,i ) } %w(ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt).each{|s| find_seq( seq,s) } 2_1 1.226768813 2_1 1.184698934 2_1 1.198623652 2_1 1.232736735 2_1 1.236094696 2_1_gc_patched 1.297389776 2_1_gc_patched 1.265118783 2_1_gc_patched 1.245833394 2_1_gc_patched 1.226823833 2_1_gc_patched 1.217403654 2_1a 1.229541257 2_1a 1.201097834 2_1a 1.197533561 2_1a 1.290960168 2_1a 1.196748172 ----------------------------------------------------------- so_lists #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby NUM = 300 SIZE = 10000 def test_lists() # create a list of integers (Li1) from 1 to SIZE li1 = (1..SIZE).to_a # copy the list to li2 (not by individual items) li2 = li1.dup # remove each individual item from left side of li2 and # append to right side of li3 (preserving order) li3 = Array.new while (not li2.empty?) li3.push(li2.shift) end # li2 must now be empty # remove each individual item from right side of li3 and # append to right side of li2 (reversing list) while (not li3.empty?) li2.push(li3.pop) end # li3 must now be empty # reverse li1 in place li1.reverse! # check that first item is now SIZE if li1[0] != SIZE then p "not SIZE" 0 else # compare li1 and li2 for equality if li1 != li2 then return(0) else # return the length of the list li1.length end end end i = 0 while i LIMIT_SQUARED escape = true break end end byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1) bit_num += 1 # Code is very similar for these cases, but using separate blocks # ensures we skip the shifting when it's unnecessary, which is most cases. if (bit_num == 8) print byte_acc.chr byte_acc = 0 bit_num = 0 elsif (x == count_size) byte_acc <<= (8 - bit_num) print byte_acc.chr byte_acc = 0 bit_num = 0 end end end 2_1 2.882417482 2_1 2.712161599 2_1 2.725466199 2_1 2.84983836 2_1 2.854365941 2_1_gc_patched 2.770934371 2_1_gc_patched 2.655699781 2_1_gc_patched 2.771827319 2_1_gc_patched 2.641720736 2_1_gc_patched 2.653059463 2_1a 2.57043226 2_1a 2.734838599 2_1a 2.721558928 2_1a 2.84120908 2_1a 2.751275874 ----------------------------------------------------------- so_matrix #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ n = 60 #Integer(ARGV.shift || 1) size = 40 def mkmatrix(rows, cols) count = 1 mx = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| row[j] = count count += 1 end mx[bi] = row end mx end def mmult(rows, cols, m1, m2) m3 = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| val = 0 (0 .. (cols - 1)).each do |k| val += m1.at(bi).at(k) * m2.at(k).at(j) end row[j] = val end m3[bi] = row end m3 end m1 = mkmatrix(size, size) m2 = mkmatrix(size, size) mm = Array.new n.times do mm = mmult(size, size, m1, m2) end # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}" 2_1 0.621478397 2_1 0.624058455 2_1 0.61889649 2_1 0.619615827 2_1 0.629638248 2_1_gc_patched 0.620926598 2_1_gc_patched 0.624886257 2_1_gc_patched 0.625343681 2_1_gc_patched 0.621099283 2_1_gc_patched 0.665937353 2_1a 0.619172285 2_1a 0.618390607 2_1a 0.61843095 2_1a 0.61992644 2_1a 0.617545731 ----------------------------------------------------------- so_meteor_contest #!/usr/bin/env ruby # # The Computer Language Shootout # http://shootout.alioth.debian.org # contributed by Kevin Barnes (Ruby novice) # PROGRAM: the main body is at the bottom. # 1) read about the problem here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ # 2) see how I represent a board as a bitmask by reading the blank_board comments # 3) read as your mental paths take you def print *args end # class to represent all information about a particular rotation of a particular piece class Rotation # an array (by location) containing a bit mask for how the piece maps at the given location. # if the rotation is invalid at that location the mask will contain false attr_reader :start_masks # maps a direction to a relative location. these differ depending on whether it is an even or # odd row being mapped from @@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 } @@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 } def initialize( directions ) @even_offsets, @odd_offsets = normalize_offsets( get_values( directions )) @even_mask = mask_for_offsets( @even_offsets) @odd_mask = mask_for_offsets( @odd_offsets) @start_masks = Array.new(60) # create the rotational masks by placing the base mask at the location and seeing if # 1) it overlaps the boundaries and 2) it produces a prunable board. if either of these # is true the piece cannot be placed 0.upto(59) do | offset | mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset) if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then imask = compute_required( mask, offset) @start_masks[offset] = [ mask, imask, imask | mask ] else @start_masks[offset] = false end end end def compute_required( mask, offset ) board = blank_board 0.upto(offset) { | i | board |= 1 << i } board |= mask return 0 if (!prunable(board | mask, offset)) board = flood_fill(board,58) count = 0 imask = 0 0.upto(59) do | i | if (board[i] == 0) then imask |= (1 << i) count += 1 end end (count > 0 && count < 5) ? imask : 0 end def flood_fill( board, location) return board if (board[location] == 1) board |= 1 << location row, col = location.divmod(6) board = flood_fill( board, location - 1) if (col > 0) board = flood_fill( board, location + 1) if (col < 4) if (row % 2 == 0) then board = flood_fill( board, location - 7) if (col > 0 && row > 0) board = flood_fill( board, location - 6) if (row > 0) board = flood_fill( board, location + 6) if (row < 9) board = flood_fill( board, location + 5) if (col > 0 && row < 9) else board = flood_fill( board, location - 5) if (col < 4 && row > 0) board = flood_fill( board, location - 6) if (row > 0) board = flood_fill( board, location + 6) if (row < 9) board = flood_fill( board, location + 7) if (col < 4 && row < 9) end board end # given a location, produces a list of relative locations covered by the piece at this rotation def offsets( location) if is_even( location) then @even_offsets.collect { | value | value + location } else @odd_offsets.collect { | value | value + location } end end # returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows) # this is hard to explain. imagine we have this partial board: # 0 0 0 0 0 x [positions 0-5] # 0 0 1 1 0 x [positions 6-11] # 0 0 1 0 0 x [positions 12-17] # 0 1 0 0 0 x [positions 18-23] # 0 1 0 0 0 x [positions 24-29] # 0 0 0 0 0 x [positions 30-35] # ... # The top-left of the piece is at position 8, the # board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that # sorted order. Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained # by subtracting 8 from everything. Now imagine the piece shifted up and to the right so it's on an even row: # 0 0 0 1 1 x [positions 0-5] # 0 0 1 0 0 x [positions 6-11] # 0 0 1 0 0 x [positions 12-17] # 0 1 0 0 0 x [positions 18-23] # 0 0 0 0 0 x [positions 24-29] # 0 0 0 0 0 x [positions 30-35] # ... # Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the # offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what # this function would return def normalize_offsets( values) min = values.min even_min = is_even(min) other_min = even_min ? min + 6 : min + 7 other_values = values.collect do | value | if is_even(value) then value + 6 - other_min else value + 7 - other_min end end values.collect! { | value | value - min } if even_min then [values, other_values] else [other_values, values] end end # produce a bitmask representation of an array of offset locations def mask_for_offsets( offsets ) mask = 0 offsets.each { | value | mask = mask + ( 1 << value ) } mask end # finds a "safe" position that a position as described by a list of directions can be placed # without falling off any edge of the board. the values returned a location to place the first piece # at so it will fit after making the described moves def start_adjust( directions ) south = east = 0; directions.each do | direction | east += 1 if ( direction == :sw || direction == :nw || direction == :west ) south += 1 if ( direction == :nw || direction == :ne ) end south * 6 + east end # given a set of directions places the piece (as defined by a set of directions) on the board at # a location that will not take it off the edge def get_values ( directions ) start = start_adjust(directions) values = [ start ] directions.each do | direction | if (start % 12 >= 6) then start += @@rotation_odd_adder[direction] else start += @@rotation_even_adder[direction] end values += [ start ] end # some moves take you back to an existing location, we'll strip duplicates values.uniq end end # describes a piece and caches information about its rotations to as to be efficient for iteration # ATTRIBUTES: # rotations -- all the rotations of the piece # type -- a numeic "name" of the piece # masks -- an array by location of all legal rotational masks (a n inner array) for that location # placed -- the mask that this piece was last placed at (not a location, but the actual mask used) class Piece attr_reader :rotations, :type, :masks attr_accessor :placed # transform hashes that change one direction into another when you either flip or rotate a set of directions @@flip_converter = { :west => :west, :east => :east, :nw => :sw, :ne => :se, :sw => :nw, :se => :ne } @@rotate_converter = { :west => :nw, :east => :se, :nw => :ne, :ne => :east, :sw => :west, :se => :sw } def initialize( directions, type ) @type = type @rotations = Array.new(); @map = {} generate_rotations( directions ) directions.collect! { | value | @@flip_converter[value] } generate_rotations( directions ) # creates the masks AND a map that returns [location, rotation] for any given mask # this is used when a board is found and we want to draw it, otherwise the map is unused @masks = Array.new(); 0.upto(59) do | i | even = true @masks[i] = @rotations.collect do | rotation | mask = rotation.start_masks[i] @map[mask[0]] = [ i, rotation ] if (mask) mask || nil end @masks[i].compact! end end # rotates a set of directions through all six angles and adds a Rotation to the list for each one def generate_rotations( directions ) 6.times do rotations.push( Rotation.new(directions)) directions.collect! { | value | @@rotate_converter[value] } end end # given a board string, adds this piece to the board at whatever location/rotation # important: the outbound board string is 5 wide, the normal location notation is six wide (padded) def fill_string( board_string) location, rotation = @map[@placed] rotation.offsets(location).each do | offset | row, col = offset.divmod(6) board_string[ row*5 + col, 1 ] = @type.to_s end end end # a blank bit board having this form: # # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 0 0 0 0 0 1 # 1 1 1 1 1 1 # # where left lest significant bit is the top left and the most significant is the lower right # the actual board only consists of the 0 places, the 1 places are blockers to keep things from running # off the edges or bottom def blank_board 0b111111100000100000100000100000100000100000100000100000100000100000 end def full_board 0b111111111111111111111111111111111111111111111111111111111111111111 end # determines if a location (bit position) is in an even row def is_even( location) (location % 12) < 6 end # support function that create three utility maps: # $converter -- for each row an array that maps a five bit row (via array mapping) # to the a a five bit representation of the bits below it # $bit_count -- maps a five bit row (via array mapping) to the number of 1s in the row # @@new_regions -- maps a five bit row (via array mapping) to an array of "region" arrays # a region array has three values the first is a mask of bits in the region, # the second is the count of those bits and the third is identical to the first # examples: # 0b10010 => [ 0b01100, 2, 0b01100 ], [ 0b00001, 1, 0b00001] # 0b01010 => [ 0b10000, 1, 0b10000 ], [ 0b00100, 1, 0b00100 ], [ 0b00001, 1, 0b00001] # 0b10001 => [ 0b01110, 3, 0b01110 ] def create_collector_support odd_map = [0b11, 0b110, 0b1100, 0b11000, 0b10000] even_map = [0b1, 0b11, 0b110, 0b1100, 0b11000] all_odds = Array.new(0b100000) all_evens = Array.new(0b100000) bit_counts = Array.new(0b100000) new_regions = Array.new(0b100000) 0.upto(0b11111) do | i | bit_count = odd = even = 0 0.upto(4) do | bit | if (i[bit] == 1) then bit_count += 1 odd |= odd_map[bit] even |= even_map[bit] end end all_odds[i] = odd all_evens[i] = even bit_counts[i] = bit_count new_regions[i] = create_regions( i) end $converter = [] 10.times { | row | $converter.push((row % 2 == 0) ? all_evens : all_odds) } $bit_counts = bit_counts $regions = new_regions.collect { | set | set.collect { | value | [ value, bit_counts[value], value] } } end # determines if a board is punable, meaning that there is no possibility that it # can be filled up with pieces. A board is prunable if there is a grouping of unfilled spaces # that are not a multiple of five. The following board is an example of a prunable board: # 0 0 1 0 0 # 0 1 0 0 0 # 1 1 0 0 0 # 0 1 0 0 0 # 0 0 0 0 0 # ... # # This board is prunable because the top left corner is only 3 bits in area, no piece will ever fit it # parameters: # board -- an initial bit board (6 bit padded rows, see blank_board for format) # location -- starting location, everything above and to the left is already full # slotting -- set to true only when testing initial pieces, when filling normally # additional assumptions are possible # # Algorithm: # The algorithm starts at the top row (as determined by location) and iterates a row at a time # maintainng counts of active open areas (kept in the collector array) each collector contains # three values at the start of an iteration: # 0: mask of bits that would be adjacent to the collector in this row # 1: the number of bits collected so far # 2: a scratch space starting as zero, but used during the computation to represent # the empty bits in the new row that are adjacent (position 0) # The exact procedure is described in-code def prunable( board, location, slotting = false) collectors = [] # loop across the rows (location / 6).to_i.upto(9) do | row_on | # obtain a set of regions representing the bits of the current row. regions = $regions[(board >> (row_on * 6)) & 0b11111] converter = $converter[row_on] # track the number of collectors at the start of the cycle so that # we don't compute against newly created collectors, only existing collectors initial_collector_count = collectors.length # loop against the regions. For each region of the row # we will see if it connects to one or more existing collectors. # if it connects to 1 collector, the bits from the region are added to the # bits of the collector and the mask is placed in collector[2] # If the region overlaps more than one collector then all the collectors # it overlaps with are merged into the first one (the others are set to nil in the array) # if NO collectors are found then the region is copied as a new collector regions.each do | region | collector_found = nil region_mask = region[2] initial_collector_count.times do | collector_num | collector = collectors[collector_num] if (collector) then collector_mask = collector[0] if (collector_mask & region_mask != 0) then if (collector_found) then collector_found[0] |= collector_mask collector_found[1] += collector[1] collector_found[2] |= collector[2] collectors[collector_num] = nil else collector_found = collector collector[1] += region[1] collector[2] |= region_mask end end end end if (collector_found == nil) then collectors.push(Array.new(region)) end end # check the existing collectors, if any collector overlapped no bits in the region its [2] value will # be zero. The size of any such reaason is tested if it is not a multiple of five true is returned since # the board is prunable. if it is a multiple of five it is removed. # Collector that are still active have a new adjacent value [0] set based n the matched bits # and have [2] cleared out for the next cycle. collectors.length.times do | collector_num | collector = collectors[collector_num] if (collector) then if (collector[2] == 0) then return true if (collector[1] % 5 != 0) collectors[collector_num] = nil else # if a collector matches all bits in the row then we can return unprunable early for the # following reasons: # 1) there can be no more unavailable bits bince we fill from the top left downward # 2) all previous regions have been closed or joined so only this region can fail # 3) this region must be good since there can never be only 1 region that is nuot # a multiple of five # this rule only applies when filling normally, so we ignore the rule if we are "slotting" # in pieces to see what configurations work for them (the only other time this algorithm is used). return false if (collector[2] == 0b11111 && !slotting) collector[0] = converter[collector[2]] collector[2] = 0 end end end # get rid of all the empty converters for the next round collectors.compact! end return false if (collectors.length <= 1) # 1 collector or less and the region is fine collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size end # creates a region given a row mask. see prunable for what a "region" is def create_regions( value ) regions = [] cur_region = 0 5.times do | bit | if (value[bit] == 0) then cur_region |= 1 << bit else if (cur_region != 0 ) then regions.push( cur_region) cur_region = 0; end end end regions.push(cur_region) if (cur_region != 0) regions end # find up to the counted number of solutions (or all solutions) and prints the final result def find_all find_top( 1) find_top( 0) print_results end # show the board def print_results print "#{@boards_found} solutions found\n\n" print_full_board( @min_board) print "\n" print_full_board( @max_board) print "\n" end # finds solutions. This special version of the main function is only used for the top level # the reason for it is basically to force a particular ordering on how the rotations are tested for # the first piece. It is called twice, first looking for placements of the odd rotations and then # looking for placements of the even locations. # # WHY? # Since any found solution has an inverse we want to maximize finding solutions that are not already found # as an inverse. The inverse will ALWAYS be 3 one of the piece configurations that is exactly 3 rotations away # (an odd number). Checking even vs odd then produces a higher probability of finding more pieces earlier # in the cycle. We still need to keep checking all the permutations, but our probability of finding one will # diminsh over time. Since we are TOLD how many to search for this lets us exit before checking all pieces # this bennifit is very great when seeking small numbers of solutions and is 0 when looking for more than the # maximum number def find_top( rotation_skip) board = blank_board (@pieces.length-1).times do piece = @pieces.shift piece.masks[0].each do | mask, imask, cmask | if ((rotation_skip += 1) % 2 == 0) then piece.placed = mask find( 1, 1, board | mask) end end @pieces.push(piece) end piece = @pieces.shift @pieces.push(piece) end # the normail find routine, iterates through the available pieces, checks all rotations at the current location # and adds any boards found. depth is acheived via recursion. the overall approach is described # here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ # parameters: # start_location -- where to start looking for place for the next piece at # placed -- number of pieces placed # board -- current state of the board # # see in-code comments def find( start_location, placed, board) # find the next location to place a piece by looking for an empty bit while board[start_location] == 1 start_location += 1 end @pieces.length.times do piece = @pieces.shift piece.masks[start_location].each do | mask, imask, cmask | if ( board & cmask == imask) then piece.placed = mask if (placed == 9) then add_board else find( start_location + 1, placed + 1, board | mask) end end end @pieces.push(piece) end end # print the board def print_full_board( board_string) 10.times do | row | print " " if (row % 2 == 1) 5.times do | col | print "#{board_string[row*5 + col,1]} " end print "\n" end end # when a board is found we "draw it" into a string and then flip that string, adding both to # the list (hash) of solutions if they are unique. def add_board board_string = "99999999999999999999999999999999999999999999999999" @all_pieces.each { | piece | piece.fill_string( board_string ) } save( board_string) save( board_string.reverse) end # adds a board string to the list (if new) and updates the current best/worst board def save( board_string) if (@all_boards[board_string] == nil) then @min_board = board_string if (board_string < @min_board) @max_board = board_string if (board_string > @max_board) @all_boards.store(board_string,true) @boards_found += 1 # the exit motif is a time saver. Ideally the function should return, but those tests # take noticeable time (performance). if (@boards_found == @stop_count) then print_results exit(0) end end end ## ## MAIN BODY :) ## create_collector_support @pieces = [ Piece.new( [ :nw, :ne, :east, :east ], 2), Piece.new( [ :ne, :se, :east, :ne ], 7), Piece.new( [ :ne, :east, :ne, :nw ], 1), Piece.new( [ :east, :sw, :sw, :se ], 6), Piece.new( [ :east, :ne, :se, :ne ], 5), Piece.new( [ :east, :east, :east, :se ], 0), Piece.new( [ :ne, :nw, :se, :east, :se ], 4), Piece.new( [ :se, :se, :se, :west ], 9), Piece.new( [ :se, :se, :east, :se ], 8), Piece.new( [ :east, :east, :sw, :se ], 3) ]; @all_pieces = Array.new( @pieces) @min_board = "99999999999999999999999999999999999999999999999999" @max_board = "00000000000000000000000000000000000000000000000000" @stop_count = ARGV[0].to_i || 2089 @all_boards = {} @boards_found = 0 find_all ######## DO IT!!! 2_1 2.94306074 2_1 2.977577508 2_1 3.060571935 2_1 2.953759348 2_1 2.953226587 2_1_gc_patched 2.903330705 2_1_gc_patched 3.054436469 2_1_gc_patched 2.929038386 2_1_gc_patched 2.947009744 2_1_gc_patched 2.926766644 2_1a 3.014633841 2_1a 2.980399051 2_1a 3.040309178 2_1a 2.952072856 2_1a 2.952300741 ----------------------------------------------------------- so_nbody # The Computer Language Shootout # http://shootout.alioth.debian.org # # Optimized for Ruby by Jesse Millikan # From version ported by Michael Neumann from the C gcc version, # which was written by Christoph Bauer. SOLAR_MASS = 4 * Math::PI**2 DAYS_PER_YEAR = 365.24 def _puts *args end class Planet attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass def initialize(x, y, z, vx, vy, vz, mass) @x, @y, @z = x, y, z @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR @mass = mass * SOLAR_MASS end def move_from_i(bodies, nbodies, dt, i) while i < nbodies b2 = bodies[i] dx = @x - b2.x dy = @y - b2.y dz = @z - b2.z distance = Math.sqrt(dx * dx + dy * dy + dz * dz) mag = dt / (distance * distance * distance) b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag @vx -= dx * b2_mass_mag @vy -= dy * b2_mass_mag @vz -= dz * b2_mass_mag b2.vx += dx * b_mass_mag b2.vy += dy * b_mass_mag b2.vz += dz * b_mass_mag i += 1 end @x += dt * @vx @y += dt * @vy @z += dt * @vz end end def energy(bodies) e = 0.0 nbodies = bodies.size for i in 0 ... nbodies b = bodies[i] e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz) for j in (i + 1) ... nbodies b2 = bodies[j] dx = b.x - b2.x dy = b.y - b2.y dz = b.z - b2.z distance = Math.sqrt(dx * dx + dy * dy + dz * dz) e -= (b.mass * b2.mass) / distance end end e end def offset_momentum(bodies) px, py, pz = 0.0, 0.0, 0.0 for b in bodies m = b.mass px += b.vx * m py += b.vy * m pz += b.vz * m end b = bodies[0] b.vx = - px / SOLAR_MASS b.vy = - py / SOLAR_MASS b.vz = - pz / SOLAR_MASS end BODIES = [ # sun Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0), # jupiter Planet.new( 4.84143144246472090e+00, -1.16032004402742839e+00, -1.03622044471123109e-01, 1.66007664274403694e-03, 7.69901118419740425e-03, -6.90460016972063023e-05, 9.54791938424326609e-04), # saturn Planet.new( 8.34336671824457987e+00, 4.12479856412430479e+00, -4.03523417114321381e-01, -2.76742510726862411e-03, 4.99852801234917238e-03, 2.30417297573763929e-05, 2.85885980666130812e-04), # uranus Planet.new( 1.28943695621391310e+01, -1.51111514016986312e+01, -2.23307578892655734e-01, 2.96460137564761618e-03, 2.37847173959480950e-03, -2.96589568540237556e-05, 4.36624404335156298e-05), # neptune Planet.new( 1.53796971148509165e+01, -2.59193146099879641e+01, 1.79258772950371181e-01, 2.68067772490389322e-03, 1.62824170038242295e-03, -9.51592254519715870e-05, 5.15138902046611451e-05) ] init = 200_000 # ARGV[0] n = Integer(init) offset_momentum(BODIES) puts "%.9f" % energy(BODIES) nbodies = BODIES.size dt = 0.01 n.times do i = 0 while i < nbodies b = BODIES[i] b.move_from_i(BODIES, nbodies, dt, i + 1) i += 1 end end puts "%.9f" % energy(BODIES) 2_1 1.644827905 2_1 1.717029517 2_1 1.637764781 2_1 1.738651153 2_1 1.711269463 2_1_gc_patched 1.809188097 2_1_gc_patched 1.682211693 2_1_gc_patched 1.689156052 2_1_gc_patched 1.787732333 2_1_gc_patched 1.786979611 2_1a 1.740925548 2_1a 1.740263145 2_1a 1.750427891 2_1a 1.719964058 2_1a 1.722049017 ----------------------------------------------------------- so_nested_loop #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # from Avi Bryant n = 16 # Integer(ARGV.shift || 1) x = 0 n.times do n.times do n.times do n.times do n.times do n.times do x += 1 end end end end end end # puts x 2_1 0.958028467 2_1 1.16233688 2_1 0.958236153 2_1 0.957801028 2_1 1.194536285 2_1_gc_patched 0.961460529 2_1_gc_patched 0.965372956 2_1_gc_patched 0.974930483 2_1_gc_patched 0.960815989 2_1_gc_patched 0.964182563 2_1a 0.972337266 2_1a 0.958275813 2_1a 1.182028314 2_1a 0.977711906 2_1a 0.969066388 ----------------------------------------------------------- so_nsieve # The Computer Language Shootout # http://shootout.alioth.debian.org/ # # contributed by Glenn Parker, March 2005 # modified by Evan Phoenix, Sept 2006 def sieve(m) flags = Flags.dup[0,m] count = 0 pmax = m - 1 p = 2 while p <= pmax unless flags[p].zero? count += 1 mult = p while mult <= pmax flags[mult] = 0 mult += p end end p += 1 end count end n = 9 # (ARGV[0] || 2).to_i Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*") n.downto(n-2) do |exponent| break if exponent < 0 m = (1 << exponent) * 10_000 # m = (2 ** exponent) * 10_000 count = sieve(m) printf "Primes up to %8d %8d\n", m, count end 2_1 2.194509967 2_1 1.932257872 2_1 1.935346469 2_1 2.008438055 2_1 1.938276703 2_1_gc_patched 1.932735229 2_1_gc_patched 1.921373551 2_1_gc_patched 1.917336377 2_1_gc_patched 1.935416561 2_1_gc_patched 1.919903841 2_1a 2.028871262 2_1a 2.055229571 2_1a 1.925299244 2_1a 2.209639011 2_1a 2.065452566 ----------------------------------------------------------- so_nsieve_bits #!/usr/bin/ruby #coding: us-ascii # # The Great Computer Language Shootout # http://shootout.alioth.debian.org/ # # nsieve-bits in Ruby # Contributed by Glenn Parker, March 2005 CharExponent = 3 BitsPerChar = 1 << CharExponent LowMask = BitsPerChar - 1 def sieve(m) items = "\xFF" * ((m / BitsPerChar) + 1) masks = "" BitsPerChar.times do |b| masks << (1 << b).chr end count = 0 pmax = m - 1 2.step(pmax, 1) do |p| if items[p >> CharExponent][p & LowMask] == 1 count += 1 p.step(pmax, p) do |mult| a = mult >> CharExponent b = mult & LowMask items[a] -= masks[b] if items[a][b] != 0 end end end count end n = 9 # (ARGV[0] || 2).to_i n.step(n - 2, -1) do |exponent| break if exponent < 0 m = 2 ** exponent * 10_000 count = sieve(m) printf "Primes up to %8d %8d\n", m, count end 2_1 2.184214255 2_1 2.153581093 2_1 2.195770631 2_1 2.150327045 2_1 2.135496576 2_1_gc_patched 2.200674921 2_1_gc_patched 2.226095991 2_1_gc_patched 2.136328088 2_1_gc_patched 2.404159489 2_1_gc_patched 2.173248905 2_1a 2.23018747 2_1a 2.187975568 2_1a 2.309963608 2_1a 2.126990575 2_1a 2.278408133 ----------------------------------------------------------- so_object #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Aristarkh Zagorodnikov class Toggle def initialize(start_state) @bool = start_state end def value @bool end def activate @bool = !@bool self end end class NthToggle < Toggle def initialize(start_state, max_counter) super start_state @count_max = max_counter @counter = 0 end def activate @counter += 1 if @counter >= @count_max @bool = !@bool @counter = 0 end self end end n = 1500000 # (ARGV.shift || 1).to_i toggle = Toggle.new 1 5.times do toggle.activate.value ? 'true' : 'false' end n.times do toggle = Toggle.new 1 end ntoggle = NthToggle.new 1, 3 8.times do ntoggle.activate.value ? 'true' : 'false' end n.times do ntoggle = NthToggle.new 1, 3 end 2_1 0.731125496 2_1 0.787444149 2_1 0.791983345 2_1 0.739341384 2_1 0.729245902 2_1_gc_patched 0.778201973 2_1_gc_patched 0.799526624 2_1_gc_patched 0.819195411 2_1_gc_patched 0.771802592 2_1_gc_patched 0.777429258 2_1a 0.773127373 2_1a 0.787003011 2_1a 0.824783691 2_1a 0.791738316 2_1a 0.790103673 ----------------------------------------------------------- so_partial_sums n = 2_500_000 # (ARGV.shift || 1).to_i alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0 1.upto(n) do |d| d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d) s0 += (2.0 / 3.0) ** (d - 1.0) s1 += 1.0 / Math.sqrt(d) s2 += 1.0 / (d * (d + 1.0)) s3 += 1.0 / (d3 * ds * ds) s4 += 1.0 / (d3 * dc * dc) s5 += 1.0 / d s6 += 1.0 / d2 s7 += alt / d s8 += alt / (2.0 * d - 1.0) alt = -alt end if false printf("%.9f\t(2/3)^k\n", s0) printf("%.9f\tk^-0.5\n", s1) printf("%.9f\t1/k(k+1)\n", s2) printf("%.9f\tFlint Hills\n", s3) printf("%.9f\tCookson Hills\n", s4) printf("%.9f\tHarmonic\n", s5) printf("%.9f\tRiemann Zeta\n", s6) printf("%.9f\tAlternating Harmonic\n", s7) printf("%.9f\tGregory\n", s8) end 2_1 2.757359592 2_1 2.750509563 2_1 2.820408422 2_1 2.714211083 2_1 2.760958135 2_1_gc_patched 2.723126024 2_1_gc_patched 2.879210978 2_1_gc_patched 2.709832349 2_1_gc_patched 2.779815704 2_1_gc_patched 2.760965363 2_1a 2.860101 2_1a 2.793708158 2_1a 2.771824768 2_1a 2.721647473 2_1a 2.759760532 ----------------------------------------------------------- so_pidigits # The Great Computer Language Shootout # http://shootout.alioth.debian.org/ # # contributed by Gabriele Renzi class PiDigitSpigot def initialize() @z = Transformation.new 1,0,0,1 @x = Transformation.new 0,0,0,0 @inverse = Transformation.new 0,0,0,0 end def next! @y = @z.extract(3) if safe? @y @z = produce(@y) @y else @z = consume @x.next!() next!() end end def safe?(digit) digit == @z.extract(4) end def produce(i) @inverse.qrst(10,-10*i,0,1).compose(@z) end def consume(a) @z.compose(a) end end class Transformation attr_reader :q, :r, :s, :t def initialize (q, r, s, t) @q,@r,@s,@t,@k = q,r,s,t,0 end def next!() @q = @k = @k + 1 @r = 4 * @k + 2 @s = 0 @t = 2 * @k + 1 self end def extract(j) (@q * j + @r) / (@s * j + @t) end def compose(a) self.class.new( @q * a.q, @q * a.r + r * a.t, @s * a.q + t * a.s, @s * a.r + t * a.t ) end def qrst *args initialize *args self end end WIDTH = 10 n = 2_500 # Integer(ARGV[0]) j = 0 digits = PiDigitSpigot.new while n > 0 if n >= WIDTH WIDTH.times {print digits.next!} j += WIDTH else n.times {print digits.next!} (WIDTH-n).times {print " "} j += n end puts "\t:"+j.to_s n -= WIDTH end 2_1 0.895942474 2_1 0.890346741 2_1 0.895797207 2_1 0.898230104 2_1 0.891206924 2_1_gc_patched 0.892134293 2_1_gc_patched 0.89144916 2_1_gc_patched 0.900866004 2_1_gc_patched 0.893271696 2_1_gc_patched 0.893060227 2_1a 0.890705335 2_1a 0.891914627 2_1a 0.897052207 2_1a 0.897074815 2_1a 0.892653085 ----------------------------------------------------------- so_random # from http://www.bagley.org/~doug/shootout/bench/random/random.ruby IM = 139968.0 IA = 3877.0 IC = 29573.0 $last = 42.0 def gen_random(max) (max * ($last = ($last * IA + IC) % IM)) / IM end N = 3_000_000 i = 0 while i/ if seq.length != 0 revcomp(seq.join) seq=Array.new end puts $_ else $_.sub(/\n/,'') seq.push $_ end end revcomp(seq.join) 2_1 1.328177794 2_1 1.309188601 2_1 1.298496505 2_1 1.344166818 2_1 1.306706346 2_1_gc_patched 1.360572606 2_1_gc_patched 1.317054977 2_1_gc_patched 1.319844505 2_1_gc_patched 1.320733572 2_1_gc_patched 1.321633888 2_1a 1.331579229 2_1a 1.318210992 2_1a 1.337691363 2_1a 1.314833439 2_1a 1.32397171 ----------------------------------------------------------- so_sieve # from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby num = 500 count = i = j = 0 flags0 = Array.new(8192,1) k = 0 while k < num k += 1 count = 0 flags = flags0.dup i = 2 while i<8192 i += 1 if flags[i] # remove all multiples of prime: i j = i*i while j < 8192 j += i flags[j] = nil end count += 1 end end end count 2_1 0.532238877 2_1 0.539417883 2_1 0.540164983 2_1 0.537884271 2_1 0.548253013 2_1_gc_patched 0.634495817 2_1_gc_patched 0.620049432 2_1_gc_patched 0.616956189 2_1_gc_patched 0.720902203 2_1_gc_patched 0.612649508 2_1a 0.551909342 2_1a 0.537387688 2_1a 0.539822672 2_1a 0.538719791 2_1a 0.539419814 ----------------------------------------------------------- so_spectralnorm # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura def eval_A(i,j) return 1.0/((i+j)*(i+j+1)/2+i+1) end def eval_A_times_u(u) v, i = nil, nil (0..u.length-1).collect { |i| v = 0 for j in 0..u.length-1 v += eval_A(i,j)*u[j] end v } end def eval_At_times_u(u) v, i = nil, nil (0..u.length-1).collect{|i| v = 0 for j in 0..u.length-1 v += eval_A(j,i)*u[j] end v } end def eval_AtA_times_u(u) return eval_At_times_u(eval_A_times_u(u)) end n = 500 # ARGV[0].to_i u=[1]*n for i in 1..10 v=eval_AtA_times_u(u) u=eval_AtA_times_u(v) end vBv=0 vv=0 for i in 0..n-1 vBv += u[i]*v[i] vv += v[i]*v[i] end str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n" # print str 2_1 2.185778574 2_1 2.202567262 2_1 2.203861466 2_1 2.310342938 2_1 2.326257622 2_1_gc_patched 2.282782942 2_1_gc_patched 2.332920422 2_1_gc_patched 2.316816857 2_1_gc_patched 2.343072423 2_1_gc_patched 2.274570127 2_1a 2.317097406 2_1a 2.210065142 2_1a 2.207935758 2_1a 2.409348507 2_1a 2.206349266 ----------------------------------------------------------- vm1_attr_ivar class C attr_reader :a, :b def initialize @a = nil @b = nil end end obj = C.new i = 0 while i<30_000_000 # while loop 1 i += 1 j = obj.a k = obj.b end 2_1 1.531629629 2_1 1.580390792 2_1 1.540548426 2_1 1.536153304 2_1 1.525006889 2_1_gc_patched 1.499092568 2_1_gc_patched 1.472946715 2_1_gc_patched 1.472556175 2_1_gc_patched 1.485543044 2_1_gc_patched 1.480762895 2_1a 1.524424608 2_1a 1.768444356 2_1a 1.637450993 2_1a 1.533095085 2_1a 1.525141797 ----------------------------------------------------------- vm1_attr_ivar_set class C attr_accessor :a, :b def initialize @a = nil @b = nil end end obj = C.new i = 0 while i<30_000_000 # while loop 1 i += 1 obj.a = 1 obj.b = 2 end 2_1 1.737911516 2_1 1.759952834 2_1 1.736466051 2_1 1.735606176 2_1 1.727523773 2_1_gc_patched 2.380314223 2_1_gc_patched 1.775108727 2_1_gc_patched 1.685194027 2_1_gc_patched 1.695317429 2_1_gc_patched 2.064428844 2_1a 1.768316789 2_1a 1.741591004 2_1a 1.730750698 2_1a 1.722066854 2_1a 1.83551376 ----------------------------------------------------------- vm1_block def m yield end i = 0 while i<30_000_000 # while loop 1 i += 1 m{ } end 2_1 2.39625345 2_1 2.816713972 2_1 2.758622082 2_1 1.99324519 2_1 2.729432524 2_1_gc_patched 2.796200224 2_1_gc_patched 2.025346354 2_1_gc_patched 2.261492895 2_1_gc_patched 2.012186824 2_1_gc_patched 1.969885256 2_1a 2.27937816 2_1a 2.703743469 2_1a 2.708023462 2_1a 2.681178491 2_1a 2.492147265 ----------------------------------------------------------- vm1_const Const = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = Const k = Const end 2_1 1.501187087 2_1 1.46980538 2_1 1.147250363 2_1 1.148293094 2_1 1.153082501 2_1_gc_patched 1.088545842 2_1_gc_patched 1.09306147 2_1_gc_patched 1.083130909 2_1_gc_patched 1.151357717 2_1_gc_patched 1.093137633 2_1a 1.149628584 2_1a 1.147267078 2_1a 1.511266795 2_1a 1.149347024 2_1a 1.149927683 ----------------------------------------------------------- vm1_ensure i = 0 while i<30_000_000 # benchmark loop 1 i += 1 begin begin ensure end ensure end end 2_1 0.637177101 2_1 0.649163671 2_1 0.634734545 2_1 0.63283661 2_1 0.634852731 2_1_gc_patched 0.964641933 2_1_gc_patched 0.948508687 2_1_gc_patched 0.955332284 2_1_gc_patched 0.960479813 2_1_gc_patched 0.962842177 2_1a 0.633064383 2_1a 0.642621029 2_1a 0.637985035 2_1a 0.637679773 2_1a 0.634340615 ----------------------------------------------------------- vm1_float_simple i = 0.0; f = 0.0 while i<30_000_000 i += 1 f += 0.1; f -= 0.1 f += 0.1; f -= 0.1 f += 0.1; f -= 0.1 end 2_1 6.053254415 2_1 5.486358511 2_1 5.692335683 2_1 6.861842866 2_1 5.642336066 2_1_gc_patched 5.476948467 2_1_gc_patched 5.497799683 2_1_gc_patched 5.806388934 2_1_gc_patched 5.484744945 2_1_gc_patched 5.502195203 2_1a 5.487222734 2_1a 6.741926829 2_1a 5.514923194 2_1a 6.849604571 2_1a 5.891961914 ----------------------------------------------------------- vm1_gc_short_lived i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end 2_1 9.771896178 2_1 9.792436785 2_1 9.775068178 2_1 9.782763275 2_1 10.141486423 2_1_gc_patched 10.028330264 2_1_gc_patched 10.037693202 2_1_gc_patched 10.031593607 2_1_gc_patched 10.733767392 2_1_gc_patched 10.029990147 2_1a 9.789618415 2_1a 10.256118424 2_1a 9.782924624 2_1a 9.785440728 2_1a 9.783838978 ----------------------------------------------------------- vm1_gc_short_with_complex_long def nested_hash h, n if n == 0 '' else 10.times{ h[Object.new] = nested_hash(h, n-1) } end end long_lived = Hash.new nested_hash long_lived, 6 GC.start GC.start i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end 2_1 11.140147573 2_1 11.100058377 2_1 11.510037488 2_1 11.110005744 2_1 11.090269445 2_1_gc_patched 11.31859146 2_1_gc_patched 11.35051067 2_1_gc_patched 11.384867864 2_1_gc_patched 11.695333429 2_1_gc_patched 11.720963899 2_1a 11.149016844 2_1a 11.094097879 2_1a 11.120396217 2_1a 11.508571468 2_1a 11.111337364 ----------------------------------------------------------- vm1_gc_short_with_long long_lived = Array.new(1_000_000){|i| "#{i}"} GC.start GC.start i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end 2_1 10.965433919 2_1 10.5837705 2_1 10.577730809 2_1 11.019021285 2_1 10.573640896 2_1_gc_patched 10.857622203 2_1_gc_patched 10.814247793 2_1_gc_patched 10.86833284 2_1_gc_patched 10.832435444 2_1_gc_patched 10.983078518 2_1a 10.584015156 2_1a 10.569543045 2_1a 10.57624269 2_1a 10.913372569 2_1a 10.579893508 ----------------------------------------------------------- vm1_gc_short_with_symbol # make many symbols 50_000.times{|i| sym = "sym#{i}".to_sym} GC.start GC.start i = 0 while i<30_000_000 # while loop 1 a = '' # short-lived String b = '' c = '' d = '' e = '' f = '' i+=1 end 2_1 9.831505017 2_1 9.782564865 2_1 9.805094099 2_1 9.79648162 2_1 9.812068218 2_1_gc_patched 10.368439486 2_1_gc_patched 9.973559158 2_1_gc_patched 9.986589612 2_1_gc_patched 9.981467511 2_1_gc_patched 10.002870289 2_1a 9.81398309 2_1a 9.789513485 2_1a 9.79356778 2_1a 9.785347187 2_1a 9.779567386 ----------------------------------------------------------- vm1_gc_wb_ary long_lived = [] GC.start GC.start i = 0 short_lived = '' while i<30_000_000 # while loop 1 long_lived[0] = short_lived # write barrier i+=1 end 2_1 1.389168199 2_1 1.396518862 2_1 1.35950976 2_1 1.370284465 2_1 1.390100745 2_1_gc_patched 1.388791276 2_1_gc_patched 1.355855465 2_1_gc_patched 1.33948157 2_1_gc_patched 1.815267815 2_1_gc_patched 1.3882984 2_1a 1.378081933 2_1a 1.384731183 2_1a 1.414325037 2_1a 1.385780389 2_1a 1.409618304 ----------------------------------------------------------- vm1_gc_wb_obj class C attr_accessor :foo end long_lived = C.new GC.start GC.start i = 0 short_lived = '' while i<30_000_000 # while loop 1 long_lived.foo = short_lived # write barrier i+=1 end 2_1 0.991757042 2_1 0.99402869 2_1 0.996908365 2_1 0.988956197 2_1 0.98704408 2_1_gc_patched 0.991918954 2_1_gc_patched 1.00324859 2_1_gc_patched 0.989649125 2_1_gc_patched 1.376873446 2_1_gc_patched 1.365221161 2_1a 0.98981653 2_1a 0.989780874 2_1a 1.00903415 2_1a 0.99060608 2_1a 0.993303777 ----------------------------------------------------------- vm1_ivar @a = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = @a k = @a end 2_1 1.264447383 2_1 1.260823362 2_1 1.257964041 2_1 1.262511003 2_1 1.621837197 2_1_gc_patched 1.252293984 2_1_gc_patched 1.536007023 2_1_gc_patched 1.240609378 2_1_gc_patched 1.239479136 2_1_gc_patched 1.240299024 2_1a 1.262450536 2_1a 1.261416084 2_1a 1.599334645 2_1a 1.261027982 2_1a 1.26265549 ----------------------------------------------------------- vm1_ivar_set i = 0 while i<30_000_000 # while loop 1 i += 1 @a = 1 @b = 2 end 2_1 1.32880444 2_1 1.32708389 2_1 1.326844134 2_1 1.331010413 2_1 1.652819669 2_1_gc_patched 1.584471456 2_1_gc_patched 1.915082047 2_1_gc_patched 1.569756626 2_1_gc_patched 1.263276757 2_1_gc_patched 1.747043702 2_1a 1.324445433 2_1a 1.343279862 2_1a 1.649072581 2_1a 1.658227953 2_1a 1.341018881 ----------------------------------------------------------- vm1_length a = 'abc' b = [1, 2, 3] i = 0 while i<30_000_000 # while loop 1 i += 1 a.length b.length end 2_1 1.454111487 2_1 1.153173904 2_1 1.143471834 2_1 1.157340429 2_1 1.139840424 2_1_gc_patched 1.391605848 2_1_gc_patched 1.09494506 2_1_gc_patched 1.09901179 2_1_gc_patched 1.095431484 2_1_gc_patched 1.374967428 2_1a 1.465812374 2_1a 1.141313714 2_1a 1.457166834 2_1a 1.143117791 2_1a 1.422461409 ----------------------------------------------------------- vm1_lvar_init def m v unless v # unreachable code v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = v10 = v11 = v12 = v13 = v14 = v15 = v16 = v17 = v18 = v19 = v20 = v21 = v22 = v23 = v24 = v25 = v26 = v27 = v28 = v29 = v30 = v31 = v32 = v33 = v34 = v35 = v36 = v37 = v38 = v39 = v40 = v41 = v42 = v43 = v44 = v45 = v46 = v47 = v48 = v49 = v50 = 1 end end i = 0 while i<30_000_000 # while loop 1 i += 1 m i end 2_1 1.916509836 2_1 1.916782976 2_1 1.919517854 2_1 1.916931515 2_1 1.916845451 2_1_gc_patched 2.344854024 2_1_gc_patched 1.967176886 2_1_gc_patched 1.687722052 2_1_gc_patched 2.056311046 2_1_gc_patched 2.083583787 2_1a 1.916868952 2_1a 1.918543886 2_1a 2.579081104 2_1a 1.916958628 2_1a 1.916978742 ----------------------------------------------------------- vm1_lvar_set i = 0 while i<30_000_000 # while loop 1 i += 1 a = b = c = d = e = f = g = h = j = k = l = m = n = o = p = q = r = 1 end 2_1 2.354052067 2_1 2.141054326 2_1 2.117728729 2_1 2.119313008 2_1 2.1318616 2_1_gc_patched 2.338143456 2_1_gc_patched 2.1096887 2_1_gc_patched 2.110957206 2_1_gc_patched 2.10981969 2_1_gc_patched 2.117547186 2_1a 2.353387094 2_1a 2.124706541 2_1a 2.118893517 2_1a 2.336907062 2_1a 2.12219158 ----------------------------------------------------------- vm1_neq i = 0 obj1 = Object.new obj2 = Object.new while i<30_000_000 # while loop 1 i += 1 obj1 != obj2 end 2_1 0.920684111 2_1 0.921003697 2_1 0.919125301 2_1 0.920410601 2_1 0.921253848 2_1_gc_patched 0.878750666 2_1_gc_patched 0.874216561 2_1_gc_patched 0.872885904 2_1_gc_patched 0.866387043 2_1_gc_patched 0.867163132 2_1a 0.920874062 2_1a 0.929350115 2_1a 0.919140159 2_1a 0.919105737 2_1a 0.920117974 ----------------------------------------------------------- vm1_not i = 0 obj = Object.new while i<30_000_000 # while loop 1 i += 1 !obj end 2_1 0.729226631 2_1 0.731053952 2_1 0.740074525 2_1 0.734547948 2_1 0.726455373 2_1_gc_patched 0.708523262 2_1_gc_patched 0.703865188 2_1_gc_patched 0.705174529 2_1_gc_patched 0.727341678 2_1_gc_patched 1.019183018 2_1a 0.729035276 2_1a 0.743532893 2_1a 0.73247138 2_1a 0.72855784 2_1a 0.738594722 ----------------------------------------------------------- vm1_rescue i = 0 while i<30_000_000 # while loop 1 i += 1 begin rescue end end 2_1 0.622968916 2_1 0.623355032 2_1 0.616947605 2_1 0.618413964 2_1 0.618956745 2_1_gc_patched 0.610762387 2_1_gc_patched 0.610963366 2_1_gc_patched 0.614318669 2_1_gc_patched 0.611554184 2_1_gc_patched 0.610978268 2_1a 0.623316977 2_1a 0.622451653 2_1a 0.618413036 2_1a 0.617214663 2_1a 0.618923306 ----------------------------------------------------------- vm1_simplereturn def m return 1 end i = 0 while i<30_000_000 # while loop 1 i += 1 m end 2_1 1.240599396 2_1 1.246194926 2_1 1.2460865 2_1 1.24419653 2_1 1.241799116 2_1_gc_patched 1.26016702 2_1_gc_patched 1.248517845 2_1_gc_patched 1.250451768 2_1_gc_patched 1.252430838 2_1_gc_patched 1.243010745 2_1a 1.244645466 2_1a 1.252512721 2_1a 1.249387813 2_1a 1.246846602 2_1a 1.304959548 ----------------------------------------------------------- vm1_swap a = 1 b = 2 i = 0 while i<30_000_000 # while loop 1 i += 1 a, b = b, a end 2_1 0.694258975 2_1 0.740619575 2_1 0.695661394 2_1 0.693566058 2_1 0.694199553 2_1_gc_patched 0.698076185 2_1_gc_patched 0.697194677 2_1_gc_patched 0.691294421 2_1_gc_patched 0.706741395 2_1_gc_patched 0.698427285 2_1a 0.693366145 2_1a 0.695209943 2_1a 0.695757461 2_1a 0.740684541 2_1a 0.695107507 ----------------------------------------------------------- vm1_yield def m i = 0 while i<30_000_000 # while loop 1 i += 1 yield end end m{} 2_1 1.25927683 2_1 1.251910343 2_1 1.246784319 2_1 1.24919228 2_1 1.24988268 2_1_gc_patched 1.274804032 2_1_gc_patched 1.305879494 2_1_gc_patched 1.294613606 2_1_gc_patched 1.30304256 2_1_gc_patched 1.276189788 2_1a 1.252534912 2_1a 1.267635267 2_1a 1.258279719 2_1a 1.256834245 2_1a 1.249097712 ----------------------------------------------------------- vm2_array i = 0 while i<6_000_000 # benchmark loop 2 i += 1 a = [1,2,3,4,5,6,7,8,9,10] end 2_1 0.729876279 2_1 0.731938531 2_1 0.757132235 2_1 0.732113413 2_1 0.732002843 2_1_gc_patched 0.732925262 2_1_gc_patched 0.715287015 2_1_gc_patched 0.718780513 2_1_gc_patched 0.714695022 2_1_gc_patched 0.713236492 2_1a 0.833086548 2_1a 0.834297815 2_1a 0.829564 2_1a 0.729540756 2_1a 0.738084263 ----------------------------------------------------------- vm2_bigarray i = 0 while i<6_000_000 # benchmark loop 2 i += 1 a = [ 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, 1,2,3,4,5,6,7,8,9,10, ] end 2_1 4.775989054 2_1 4.779822841 2_1 4.771577893 2_1 4.748117028 2_1 4.810297339 2_1_gc_patched 4.668107305 2_1_gc_patched 4.717723928 2_1_gc_patched 4.728617093 2_1_gc_patched 4.711658671 2_1_gc_patched 4.688457658 2_1a 4.766680951 2_1a 4.763857057 2_1a 4.769374466 2_1a 4.779997401 2_1a 4.670049481 ----------------------------------------------------------- vm2_bighash i = 0 while i<60_000 # benchmark loop 2 i += 1 a = {0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 19=>19, 20=>20, 21=>21, 22=>22, 23=>23, 24=>24, 25=>25, 26=>26, 27=>27, 28=>28, 29=>29, 30=>30, 31=>31, 32=>32, 33=>33, 34=>34, 35=>35, 36=>36, 37=>37, 38=>38, 39=>39, 40=>40, 41=>41, 42=>42, 43=>43, 44=>44, 45=>45, 46=>46, 47=>47, 48=>48, 49=>49, 50=>50, 51=>51, 52=>52, 53=>53, 54=>54, 55=>55, 56=>56, 57=>57, 58=>58, 59=>59, 60=>60, 61=>61, 62=>62, 63=>63, 64=>64, 65=>65, 66=>66, 67=>67, 68=>68, 69=>69, 70=>70, 71=>71, 72=>72, 73=>73, 74=>74, 75=>75, 76=>76, 77=>77, 78=>78, 79=>79, 80=>80, 81=>81, 82=>82, 83=>83, 84=>84, 85=>85, 86=>86, 87=>87, 88=>88, 89=>89, 90=>90, 91=>91, 92=>92, 93=>93, 94=>94, 95=>95, 96=>96, 97=>97, 98=>98, 99=>99, 100=>100, 101=>101, 102=>102, 103=>103, 104=>104, 105=>105, 106=>106, 107=>107, 108=>108, 109=>109, 110=>110, 111=>111, 112=>112, 113=>113, 114=>114, 115=>115, 116=>116, 117=>117, 118=>118, 119=>119, 120=>120, 121=>121, 122=>122, 123=>123, 124=>124, 125=>125, 126=>126, 127=>127, 128=>128, 129=>129, 130=>130, 131=>131, 132=>132, 133=>133, 134=>134, 135=>135, 136=>136, 137=>137, 138=>138, 139=>139, 140=>140, 141=>141, 142=>142, 143=>143, 144=>144, 145=>145, 146=>146, 147=>147, 148=>148, 149=>149, 150=>150, 151=>151, 152=>152, 153=>153, 154=>154, 155=>155, 156=>156, 157=>157, 158=>158, 159=>159, 160=>160, 161=>161, 162=>162, 163=>163, 164=>164, 165=>165, 166=>166, 167=>167, 168=>168, 169=>169, 170=>170, 171=>171, 172=>172, 173=>173, 174=>174, 175=>175, 176=>176, 177=>177, 178=>178, 179=>179, 180=>180, 181=>181, 182=>182, 183=>183, 184=>184, 185=>185, 186=>186, 187=>187, 188=>188, 189=>189, 190=>190, 191=>191, 192=>192, 193=>193, 194=>194, 195=>195, 196=>196, 197=>197, 198=>198, 199=>199, 200=>200, 201=>201, 202=>202, 203=>203, 204=>204, 205=>205, 206=>206, 207=>207, 208=>208, 209=>209, 210=>210, 211=>211, 212=>212, 213=>213, 214=>214, 215=>215, 216=>216, 217=>217, 218=>218, 219=>219, 220=>220, 221=>221, 222=>222, 223=>223, 224=>224, 225=>225, 226=>226, 227=>227, 228=>228, 229=>229, 230=>230, 231=>231, 232=>232, 233=>233, 234=>234, 235=>235, 236=>236, 237=>237, 238=>238, 239=>239, 240=>240, 241=>241, 242=>242, 243=>243, 244=>244, 245=>245, 246=>246, 247=>247, 248=>248, 249=>249, 250=>250, 251=>251, 252=>252, 253=>253, 254=>254, 255=>255, 256=>256, 257=>257, 258=>258, 259=>259, 260=>260, 261=>261, 262=>262, 263=>263, 264=>264, 265=>265, 266=>266, 267=>267, 268=>268, 269=>269, 270=>270, 271=>271, 272=>272, 273=>273, 274=>274, 275=>275, 276=>276, 277=>277, 278=>278, 279=>279, 280=>280, 281=>281, 282=>282, 283=>283, 284=>284, 285=>285, 286=>286, 287=>287, 288=>288, 289=>289, 290=>290, 291=>291, 292=>292, 293=>293, 294=>294, 295=>295, 296=>296, 297=>297, 298=>298, 299=>299, 300=>300, 301=>301, 302=>302, 303=>303, 304=>304, 305=>305, 306=>306, 307=>307, 308=>308, 309=>309, 310=>310, 311=>311, 312=>312, 313=>313, 314=>314, 315=>315, 316=>316, 317=>317, 318=>318, 319=>319, 320=>320, 321=>321, 322=>322, 323=>323, 324=>324, 325=>325, 326=>326, 327=>327, 328=>328, 329=>329, 330=>330, 331=>331, 332=>332, 333=>333, 334=>334, 335=>335, 336=>336, 337=>337, 338=>338, 339=>339, 340=>340, 341=>341, 342=>342, 343=>343, 344=>344, 345=>345, 346=>346, 347=>347, 348=>348, 349=>349, 350=>350, 351=>351, 352=>352, 353=>353, 354=>354, 355=>355, 356=>356, 357=>357, 358=>358, 359=>359, 360=>360, 361=>361, 362=>362, 363=>363, 364=>364, 365=>365, 366=>366, 367=>367, 368=>368, 369=>369, 370=>370, 371=>371, 372=>372, 373=>373, 374=>374, 375=>375, 376=>376, 377=>377, 378=>378, 379=>379, 380=>380, 381=>381, 382=>382, 383=>383, 384=>384, 385=>385, 386=>386, 387=>387, 388=>388, 389=>389, 390=>390, 391=>391, 392=>392, 393=>393, 394=>394, 395=>395, 396=>396, 397=>397, 398=>398, 399=>399, 400=>400, 401=>401, 402=>402, 403=>403, 404=>404, 405=>405, 406=>406, 407=>407, 408=>408, 409=>409, 410=>410, 411=>411, 412=>412, 413=>413, 414=>414, 415=>415, 416=>416, 417=>417, 418=>418, 419=>419, 420=>420, 421=>421, 422=>422, 423=>423, 424=>424, 425=>425, 426=>426, 427=>427, 428=>428, 429=>429, 430=>430, 431=>431, 432=>432, 433=>433, 434=>434, 435=>435, 436=>436, 437=>437, 438=>438, 439=>439, 440=>440, 441=>441, 442=>442, 443=>443, 444=>444, 445=>445, 446=>446, 447=>447, 448=>448, 449=>449, 450=>450, 451=>451, 452=>452, 453=>453, 454=>454, 455=>455, 456=>456, 457=>457, 458=>458, 459=>459, 460=>460, 461=>461, 462=>462, 463=>463, 464=>464, 465=>465, 466=>466, 467=>467, 468=>468, 469=>469, 470=>470, 471=>471, 472=>472, 473=>473, 474=>474, 475=>475, 476=>476, 477=>477, 478=>478, 479=>479, 480=>480, 481=>481, 482=>482, 483=>483, 484=>484, 485=>485, 486=>486, 487=>487, 488=>488, 489=>489, 490=>490, 491=>491, 492=>492, 493=>493, 494=>494, 495=>495, 496=>496, 497=>497, 498=>498, 499=>499, 500=>500,} end 2_1 4.648841258 2_1 4.622638299 2_1 4.637900377 2_1 4.619187165 2_1 4.618651162 2_1_gc_patched 4.578619906 2_1_gc_patched 4.574345548 2_1_gc_patched 4.570105052 2_1_gc_patched 4.579683075 2_1_gc_patched 4.558419992 2_1a 4.643950992 2_1a 4.63541423 2_1a 4.734587344 2_1a 4.619892306 2_1a 4.615338775 ----------------------------------------------------------- vm2_case i = 0 while i<6_000_000 # while loop 2 case :foo when :bar raise when :baz raise when :boo raise when :foo i += 1 end end 2_1 0.231028206 2_1 0.228234912 2_1 0.231487534 2_1 0.229532139 2_1 0.228293086 2_1_gc_patched 0.225946698 2_1_gc_patched 0.225553467 2_1_gc_patched 0.226827805 2_1_gc_patched 0.226227989 2_1_gc_patched 0.225807259 2_1a 0.228305475 2_1a 0.229815781 2_1a 0.228461049 2_1a 0.228767071 2_1a 0.23219697 ----------------------------------------------------------- vm2_defined_method class Object define_method(:m){} end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m; m; m; m; m; m; m; m; end 2_1 2.860397018 2_1 2.860880009 2_1 2.824132616 2_1 2.903754989 2_1 2.860443635 2_1_gc_patched 3.527174242 2_1_gc_patched 2.884719598 2_1_gc_patched 2.811607312 2_1_gc_patched 2.887629413 2_1_gc_patched 3.470660688 2_1a 2.843783244 2_1a 2.997646885 2_1a 2.832459234 2_1a 2.856943885 2_1a 2.830958321 ----------------------------------------------------------- vm2_dstr i = 0 x = y = 'z' while i<6_000_000 # benchmark loop 2 i += 1 str = "foo#{x}bar#{y}baz" end 2_1 1.77581515 2_1 1.921405747 2_1 1.828355009 2_1 1.835732503 2_1 1.786322204 2_1_gc_patched 1.795016431 2_1_gc_patched 1.789502164 2_1_gc_patched 1.791899232 2_1_gc_patched 1.796326569 2_1_gc_patched 1.797456031 2_1a 1.925421947 2_1a 1.822578136 2_1a 1.776109691 2_1a 1.841553355 2_1a 1.771267733 ----------------------------------------------------------- vm2_eval i = 0 while i<6_000_000 # benchmark loop 2 i += 1 eval("1") end 2_1 17.177696247 2_1 17.824850652 2_1 17.515956779 2_1 17.09561825 2_1 16.823998527 2_1_gc_patched 16.814298078 2_1_gc_patched 17.126773452 2_1_gc_patched 16.680322475 2_1_gc_patched 17.61056813 2_1_gc_patched 16.612312742 2_1a 17.234581546 2_1a 16.913945628 2_1a 16.913493507 2_1a 16.504622582 2_1a 17.108716036 ----------------------------------------------------------- vm2_method def m nil end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m; m; m; m; m; m; m; m; end 2_1 1.310121329 2_1 1.370799558 2_1 1.437921753 2_1 1.370713464 2_1 1.370266376 2_1_gc_patched 1.343194337 2_1_gc_patched 1.378622031 2_1_gc_patched 1.318759493 2_1_gc_patched 1.313910017 2_1_gc_patched 1.390447402 2_1a 1.389224627 2_1a 1.378249441 2_1a 1.303140324 2_1a 1.309122656 2_1a 1.302026623 ----------------------------------------------------------- vm2_method_missing class C def method_missing mid end end obj = C.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; end 2_1 2.125764561 2_1 2.077706469 2_1 2.142320583 2_1 2.16457687 2_1 2.11861806 2_1_gc_patched 2.042002571 2_1_gc_patched 2.151923874 2_1_gc_patched 2.043752561 2_1_gc_patched 2.135468634 2_1_gc_patched 2.038529016 2_1a 2.10213536 2_1a 2.148823251 2_1a 2.140901409 2_1a 2.123955833 2_1a 2.079115553 ----------------------------------------------------------- vm2_method_with_block def m nil end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m{}; m{}; m{}; m{}; m{}; m{}; m{}; m{}; end 2_1 1.501131718 2_1 1.439779314 2_1 1.509052574 2_1 1.492342621 2_1 1.429910271 2_1_gc_patched 1.461101102 2_1_gc_patched 1.431134273 2_1_gc_patched 1.436893653 2_1_gc_patched 1.439194577 2_1_gc_patched 1.472955366 2_1a 1.451737017 2_1a 1.509638879 2_1a 1.52644964 2_1a 1.53903463 2_1a 1.499355543 ----------------------------------------------------------- vm2_mutex require 'thread' m = Mutex.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m.synchronize{} end 2_1 0.817767427 2_1 0.82406337 2_1 0.817781406 2_1 0.907748384 2_1 0.822498784 2_1_gc_patched 0.890209306 2_1_gc_patched 0.813709219 2_1_gc_patched 0.821070756 2_1_gc_patched 0.815636388 2_1_gc_patched 0.818401061 2_1a 0.914778416 2_1a 0.824821698 2_1a 0.820806458 2_1a 0.820170757 2_1a 0.917090902 ----------------------------------------------------------- vm2_poly_method class C1 def m 1 end end class C2 def m 2 end end o1 = C1.new o2 = C2.new i = 0 while i<6_000_000 # benchmark loop 2 o = (i % 2 == 0) ? o1 : o2 o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i += 1 end 2_1 3.82333096 2_1 2.22427556 2_1 2.308873118 2_1 2.301216865 2_1 3.242067475 2_1_gc_patched 2.20087043 2_1_gc_patched 2.236431818 2_1_gc_patched 2.21577988 2_1_gc_patched 2.277246783 2_1_gc_patched 2.261092685 2_1a 2.289693082 2_1a 2.27362761 2_1a 2.308118417 2_1a 2.32844826 2_1a 2.253225493 ----------------------------------------------------------- vm2_poly_method_ov class C1 def m 1 end end class C2 def m 2 end end o1 = C1.new o2 = C2.new i = 0 while i<6_000_000 # benchmark loop 2 o = (i % 2 == 0) ? o1 : o2 # o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i += 1 end 2_1 0.261721425 2_1 0.291862127 2_1 0.307775402 2_1 0.326984755 2_1 0.327696657 2_1_gc_patched 0.301882594 2_1_gc_patched 0.2612438 2_1_gc_patched 0.295387664 2_1_gc_patched 0.262015974 2_1_gc_patched 0.324231776 2_1a 0.29309305 2_1a 0.294004419 2_1a 0.297760725 2_1a 0.298664291 2_1a 0.294043577 ----------------------------------------------------------- vm2_proc def m &b b end pr = m{ a = 1 } i = 0 while i<6_000_000 # benchmark loop 2 i += 1 pr.call end 2_1 0.591749536 2_1 0.598513664 2_1 0.674609283 2_1 0.686658378 2_1 0.517846573 2_1_gc_patched 0.536931873 2_1_gc_patched 0.542556387 2_1_gc_patched 0.612556873 2_1_gc_patched 0.53764836 2_1_gc_patched 0.604392811 2_1a 0.518278457 2_1a 0.522773001 2_1a 0.642341383 2_1a 0.523174084 2_1a 0.591109889 ----------------------------------------------------------- vm2_raise1 def rec n if n > 0 rec n-1 else raise end end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 begin rec 1 rescue # ignore end end 2_1 7.741476781 2_1 7.727498678 2_1 7.43677125 2_1 7.823186803 2_1 7.562739834 2_1_gc_patched 7.51982946 2_1_gc_patched 7.5797513 2_1_gc_patched 8.0097839 2_1_gc_patched 7.316461827 2_1_gc_patched 7.978904699 2_1a 7.242079266 2_1a 7.833785637 2_1a 7.496428206 2_1a 7.195070081 2_1a 7.856475109 ----------------------------------------------------------- vm2_raise2 def rec n if n > 0 rec n-1 else raise end end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 begin rec 10 rescue # ignore end end 2_1 9.737087924 2_1 10.379771428 2_1 9.956040992 2_1 10.212297659 2_1 10.297366883 2_1_gc_patched 10.018173116 2_1_gc_patched 10.287696613 2_1_gc_patched 9.848683642 2_1_gc_patched 10.229509046 2_1_gc_patched 10.100762242 2_1a 10.928786028 2_1a 10.18142201 2_1a 10.118423445 2_1a 9.73362934 2_1a 10.211912638 ----------------------------------------------------------- vm2_regexp i = 0 str = 'xxxhogexxx' while i<6_000_000 # benchmark loop 2 /hoge/ =~ str i += 1 end 2_1 1.29365176 2_1 1.302089111 2_1 1.256713765 2_1 1.295435004 2_1 1.286380703 2_1_gc_patched 1.229838544 2_1_gc_patched 1.230843295 2_1_gc_patched 1.228240428 2_1_gc_patched 1.229975233 2_1_gc_patched 1.238905707 2_1a 1.23424063 2_1a 1.292016501 2_1a 1.299604049 2_1a 1.293729447 2_1a 1.267286238 ----------------------------------------------------------- vm2_send class C def m end end o = C.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 o.__send__ :m end 2_1 0.374812822 2_1 0.374804613 2_1 0.37162413 2_1 0.373927212 2_1 0.37705436 2_1_gc_patched 0.373461824 2_1_gc_patched 0.380048749 2_1_gc_patched 0.374869898 2_1_gc_patched 0.371951307 2_1_gc_patched 0.38410322 2_1a 0.379951599 2_1a 0.386678045 2_1a 0.37581297 2_1a 0.371811386 2_1a 0.3756953 ----------------------------------------------------------- vm2_super class C def m 1 end end class CC < C def m super() end end obj = CC.new i = 0 while i<6_000_000 # benchmark loop 2 obj.m i += 1 end 2_1 0.879703135 2_1 0.899400678 2_1 0.598684302 2_1 0.891145798 2_1 0.690012457 2_1_gc_patched 0.518833698 2_1_gc_patched 0.517226136 2_1_gc_patched 0.522841041 2_1_gc_patched 0.517497698 2_1_gc_patched 0.522538114 2_1a 0.528293351 2_1a 0.73981586 2_1a 0.654480054 2_1a 0.515216251 2_1a 0.78339702 ----------------------------------------------------------- vm2_unif1 i = 0 def m a, b end while i<6_000_000 # benchmark loop 2 i += 1 m 100, 200 end 2_1 0.268639253 2_1 0.269381506 2_1 0.332515052 2_1 0.270248559 2_1 0.270322077 2_1_gc_patched 0.268419105 2_1_gc_patched 0.346737549 2_1_gc_patched 0.269035832 2_1_gc_patched 0.346951177 2_1_gc_patched 0.2700908 2_1a 0.268578221 2_1a 0.270594951 2_1a 0.266711885 2_1a 0.328267378 2_1a 0.268819134 ----------------------------------------------------------- vm2_zsuper i = 0 class C def m a 1 end end class CC < C def m a super end end obj = CC.new while i<6_000_000 # benchmark loop 2 obj.m 10 i += 1 end 2_1 0.655294097 2_1 0.7657319 2_1 0.659911995 2_1 0.754683607 2_1 0.53183556 2_1_gc_patched 0.538611197 2_1_gc_patched 0.540486637 2_1_gc_patched 0.533269694 2_1_gc_patched 0.533194857 2_1_gc_patched 0.533405291 2_1a 0.755003722 2_1a 0.608190723 2_1a 0.663595773 2_1a 0.688447396 2_1a 0.690483681 ----------------------------------------------------------- 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 2_1 0.152381332 2_1 0.153285561 2_1 0.154701969 2_1 0.154493875 2_1 0.161417449 2_1_gc_patched 0.151189118 2_1_gc_patched 0.151801258 2_1_gc_patched 0.151720097 2_1_gc_patched 0.158828172 2_1_gc_patched 0.158210511 2_1a 0.160384101 2_1a 0.152611648 2_1a 0.152779461 2_1a 0.154026752 2_1a 0.154319409 ----------------------------------------------------------- vm3_clearmethodcache i = 0 while i<200_000 i += 1 Class.new{ def m; end } end 2_1 0.389801176 2_1 0.389912127 2_1 0.380266504 2_1 0.386630734 2_1 0.387454428 2_1_gc_patched 0.379597148 2_1_gc_patched 0.383598411 2_1_gc_patched 0.380452042 2_1_gc_patched 0.383554635 2_1_gc_patched 0.386381947 2_1a 0.395311887 2_1a 0.388098348 2_1a 0.38488293 2_1a 0.38310061 2_1a 0.388140134 ----------------------------------------------------------- vm3_gc #! /usr/bin/ruby 5000.times do 100.times do {"xxxx"=>"yyyy"} end GC.start end 2_1 1.787170244 2_1 1.796867125 2_1 1.794108051 2_1 1.791270878 2_1 1.803287938 2_1_gc_patched 1.781658306 2_1_gc_patched 1.771099631 2_1_gc_patched 1.767399518 2_1_gc_patched 1.762393094 2_1_gc_patched 1.795063029 2_1a 1.788810068 2_1a 1.789757751 2_1a 1.788808405 2_1a 1.788621664 2_1a 1.78786847 ----------------------------------------------------------- vm_thread_alive_check1 5_000.times{ t = Thread.new{} while t.alive? Thread.pass end } 2_1 0.132939235 2_1 0.134944921 2_1 0.135763347 2_1 0.134047161 2_1 0.135801043 2_1_gc_patched 0.135308693 2_1_gc_patched 0.1364075 2_1_gc_patched 0.136418169 2_1_gc_patched 0.134549473 2_1_gc_patched 0.136810683 2_1a 0.137268879 2_1a 0.14050069 2_1a 0.138315321 2_1a 0.139618952 2_1a 0.132772176 ----------------------------------------------------------- vm_thread_close 1000.times { Thread.new { sleep } } i = 0 while i<100_000 # benchmark loop 3 i += 1 IO.pipe.each(&:close) end 2_1 5.30253065 2_1 5.194580616 2_1 5.238015335 2_1 5.249057468 2_1 5.270430278 2_1_gc_patched 5.300936139 2_1_gc_patched 5.327954119 2_1_gc_patched 3.891713143 2_1_gc_patched 5.236571271 2_1_gc_patched 4.10252837 2_1a 5.26375214 2_1a 4.339984205 2_1a 5.317975165 2_1a 4.42233045 2_1a 5.218982942 ----------------------------------------------------------- vm_thread_create_join i = 0 while i<100_000 # benchmark loop 3 i += 1 Thread.new{ }.join end 2_1 4.784665487 2_1 4.904802662 2_1 4.754240752 2_1 4.675991744 2_1 4.792705189 2_1_gc_patched 4.868974066 2_1_gc_patched 4.726711885 2_1_gc_patched 4.586128489 2_1_gc_patched 4.845308353 2_1_gc_patched 4.770390182 2_1a 4.717029354 2_1a 4.892409423 2_1a 4.818255506 2_1a 4.829674149 2_1a 4.650621601 ----------------------------------------------------------- vm_thread_mutex1 # one thread, one mutex (no contention) require 'thread' m = Mutex.new r = 0 max = 2000 lmax = max * max (1..1).map{ Thread.new{ i = 0 while i