2014-08-14 23:11:26 +0900 target 0: trunk (ruby 2.2.0dev (2014-08-14 trunk 47178) [x86_64-linux]) at "ruby" target 1: rincgc (ruby 2.2.0dev (2014-08-12 trunk 47143) [x86_64-linux]) at "/home/ko1/tmp/gitruby/bin/ruby" ----------------------------------------------------------- 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 trunk 0.136818309 trunk 0.13537386 trunk 0.132582138 trunk 0.145255957 trunk 0.133165569 rincgc 0.151318196 rincgc 0.151771023 rincgc 0.15927123 rincgc 0.150605624 rincgc 0.164929426 ----------------------------------------------------------- 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 trunk 128.635606943 trunk 128.285666419 trunk 129.4838644 trunk 127.194210702 trunk 127.702091109 rincgc 133.053961911 rincgc 131.18850752 rincgc 132.577644029 rincgc 132.162940169 rincgc 136.549970262 ----------------------------------------------------------- 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 %>

trunk 2.748742518 trunk 2.750694586 trunk 2.758104635 trunk 2.756225129 trunk 2.753260462 rincgc 2.835191001 rincgc 2.830618825 rincgc 2.848530944 rincgc 2.846045708 rincgc 2.833310656 ----------------------------------------------------------- app_factorial def fact(n) if(n > 1) n * fact(n-1) else 1 end end 100.times { fact(5000) } trunk 2.133788801 trunk 2.18863651 trunk 2.139396237 trunk 2.123108176 trunk 2.120363746 rincgc 2.146553024 rincgc 2.118388941 rincgc 2.120781531 rincgc 2.13458816 rincgc 2.134210369 ----------------------------------------------------------- app_fib def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(34) trunk 1.257720285 trunk 1.296164592 trunk 1.255245556 trunk 1.317511821 trunk 1.309763773 rincgc 1.320558034 rincgc 1.328532939 rincgc 1.415840065 rincgc 1.30131301 rincgc 1.351272689 ----------------------------------------------------------- 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) } } trunk 2.638241576 trunk 2.734121717 trunk 2.595116521 trunk 2.631007509 trunk 2.657876574 rincgc 2.608965268 rincgc 2.695752446 rincgc 2.72086657 rincgc 2.734211496 rincgc 2.723494242 ----------------------------------------------------------- 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) trunk 36.379222841 trunk 37.22406599 trunk 36.239328552 trunk 35.578845652 trunk 35.859087629 rincgc 36.746827195 rincgc 36.377191219 rincgc 37.925446831 rincgc 37.449834014 rincgc 38.695535438 ----------------------------------------------------------- app_raise i = 0 while i<300000 i += 1 begin raise rescue end end trunk 0.785850706 trunk 0.777591593 trunk 0.780643109 trunk 0.797488906 trunk 0.787248387 rincgc 0.800874644 rincgc 0.800679555 rincgc 0.800690412 rincgc 0.797151213 rincgc 0.792532546 ----------------------------------------------------------- app_strconcat i = 0 while i<2_000_000 "#{1+1} #{1+1} #{1+1}" i += 1 end trunk 2.474878116 trunk 2.557896484 trunk 2.491239934 trunk 2.499728176 trunk 2.46273344 rincgc 2.451295402 rincgc 2.383459274 rincgc 2.490102699 rincgc 2.420359998 rincgc 2.398296942 ----------------------------------------------------------- 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) trunk 1.781744504 trunk 1.679129826 trunk 1.959816264 trunk 1.805365598 trunk 1.904027254 rincgc 1.611168994 rincgc 1.656532301 rincgc 1.727782033 rincgc 1.671778324 rincgc 1.642524582 ----------------------------------------------------------- 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) trunk 1.298134503 trunk 1.311452739 trunk 1.380652912 trunk 1.337456595 trunk 1.244679711 rincgc 1.278681394 rincgc 1.312068757 rincgc 1.277834611 rincgc 1.385711876 rincgc 1.28783898 ----------------------------------------------------------- app_uri require 'uri' 100_000.times{ uri = URI.parse('http://www.ruby-lang.org') uri.scheme uri.host uri.port } trunk 2.390006897 trunk 2.40777247 trunk 2.403700736 trunk 2.384343291 trunk 2.389068782 rincgc 2.491348495 rincgc 2.48595032 rincgc 2.490065455 rincgc 2.518472142 rincgc 2.498416793 ----------------------------------------------------------- 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] } } trunk 1.107760699 trunk 1.115502134 trunk 1.117308865 trunk 1.109179242 trunk 1.040842987 rincgc 1.1653267 rincgc 1.097755445 rincgc 1.199325311 rincgc 1.194820361 rincgc 1.122006414 ----------------------------------------------------------- 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] } } trunk 1.024887074 trunk 1.093705238 trunk 1.022712392 trunk 1.10409843 trunk 1.079045818 rincgc 1.013350404 rincgc 1.022696308 rincgc 1.008180935 rincgc 1.036581022 rincgc 1.032079047 ----------------------------------------------------------- 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] } } trunk 1.494559963 trunk 1.477802923 trunk 1.475421 trunk 1.462658299 trunk 1.480650074 rincgc 1.591894722 rincgc 1.58407729 rincgc 1.588151132 rincgc 1.575928563 rincgc 1.591645416 ----------------------------------------------------------- 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] } } trunk 3.323205482 trunk 3.365610613 trunk 3.384987708 trunk 3.361730027 trunk 3.350437694 rincgc 3.662532426 rincgc 3.678229833 rincgc 3.679598905 rincgc 3.701571727 rincgc 3.677285367 ----------------------------------------------------------- hash_flatten h = {} 10000.times do |i| h[i] = nil end 1000.times do h.flatten end trunk 0.914223598 trunk 0.920803843 trunk 0.91769886 trunk 0.914928914 trunk 0.914741336 rincgc 0.915837221 rincgc 0.920451577 rincgc 0.914597161 rincgc 0.9169173 rincgc 0.911726349 ----------------------------------------------------------- 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] } } trunk 0.832476043 trunk 0.844806162 trunk 0.819226551 trunk 0.818388939 trunk 0.836336088 rincgc 0.789899176 rincgc 0.789637995 rincgc 0.794289834 rincgc 0.793502915 rincgc 0.800126111 ----------------------------------------------------------- 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] } } trunk 0.780855863 trunk 0.773894929 trunk 0.769969068 trunk 0.811505989 trunk 0.7641915 rincgc 0.71050731 rincgc 0.719645269 rincgc 0.710696004 rincgc 0.71828273 rincgc 0.71194123 ----------------------------------------------------------- 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] } } trunk 0.738790174 trunk 0.789196027 trunk 0.752394081 trunk 0.816223522 trunk 0.761938393 rincgc 0.792364174 rincgc 0.71396864 rincgc 0.713524369 rincgc 0.732325557 rincgc 0.766516661 ----------------------------------------------------------- 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] } } trunk 0.813978155 trunk 0.822605339 trunk 0.810545735 trunk 0.815046333 trunk 0.810941859 rincgc 0.798321909 rincgc 0.805251412 rincgc 0.776759501 rincgc 0.791015804 rincgc 0.816252499 ----------------------------------------------------------- hash_keys h = {} 10000.times do |i| h[i] = nil end 5000.times do h.keys end trunk 0.466370277 trunk 0.474906124 trunk 0.46998108 trunk 0.472466284 trunk 0.467171845 rincgc 0.472935438 rincgc 0.475443275 rincgc 0.49265288 rincgc 0.47941108 rincgc 0.487510488 ----------------------------------------------------------- hash_shift h = {} 10000.times do |i| h[i] = nil end 50000.times do k, v = h.shift h[k] = v end trunk 0.09834481 trunk 0.099952516 trunk 0.098699117 trunk 0.09683726 trunk 0.096465958 rincgc 0.100089703 rincgc 0.098887501 rincgc 0.098612813 rincgc 0.098303621 rincgc 0.09871554 ----------------------------------------------------------- hash_values h = {} 10000.times do |i| h[i] = nil end 5000.times do h.values end trunk 0.47957152 trunk 0.484654974 trunk 0.477671192 trunk 0.488776689 trunk 0.480319069 rincgc 0.496040055 rincgc 0.492684956 rincgc 0.49599287 rincgc 0.479293274 rincgc 0.50346985 ----------------------------------------------------------- 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) trunk 2.568131556 trunk 2.552728396 trunk 2.521295201 trunk 2.577607687 trunk 2.528697199 rincgc 2.571660137 rincgc 2.595144431 rincgc 2.598063776 rincgc 2.579551051 rincgc 2.590199035 ----------------------------------------------------------- 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 } trunk 3.796306793 trunk 3.751295701 trunk 3.78609671 trunk 3.70854781 trunk 3.787147742 rincgc 3.764924733 rincgc 3.942172429 rincgc 3.826321492 rincgc 3.840747866 rincgc 3.85404139 ----------------------------------------------------------- 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 } trunk 2.421710642 trunk 2.440599591 trunk 2.417628621 trunk 2.387125524 trunk 2.640249271 rincgc 2.497823055 rincgc 2.599122381 rincgc 2.547611875 rincgc 2.4963605 rincgc 2.486084905 ----------------------------------------------------------- io_select # IO.select performance w = [ IO.pipe[1] ]; nr = 1000000 nr.times { IO.select nil, w } trunk 3.288332149 trunk 3.335469245 trunk 3.257901943 trunk 3.401198985 trunk 3.305118014 rincgc 3.53506487 rincgc 3.592197188 rincgc 3.664101673 rincgc 3.590013904 rincgc 3.637546077 ----------------------------------------------------------- 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 trunk 4.176161211 trunk 4.017850781 trunk 4.129209719 trunk 4.039713706 trunk 3.996796824 rincgc 4.486286006 rincgc 4.331410107 rincgc 4.356420995 rincgc 4.346843761 rincgc 4.427724365 ----------------------------------------------------------- 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 trunk 0.096284605 trunk 0.096037937 trunk 0.095781082 trunk 0.09579916 trunk 0.095809693 rincgc 0.097087045 rincgc 0.097171175 rincgc 0.096484581 rincgc 0.09693112 rincgc 0.097124299 ----------------------------------------------------------- loop_for for i in 1..30_000_000 # end trunk 2.616311283 trunk 2.644996737 trunk 2.614695631 trunk 2.720473154 trunk 2.614750534 rincgc 2.637275586 rincgc 2.637555433 rincgc 2.663712054 rincgc 2.702688212 rincgc 2.638137779 ----------------------------------------------------------- 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 trunk 1.004583431 trunk 0.999911581 trunk 0.997516362 trunk 1.00102752 trunk 1.008056159 rincgc 1.006882197 rincgc 1.026023357 rincgc 1.010918153 rincgc 1.00628388 rincgc 1.017091611 ----------------------------------------------------------- loop_times 30_000_000.times{|e|} trunk 2.494536745 trunk 2.614320497 trunk 2.494549781 trunk 2.494063724 trunk 2.520575765 rincgc 2.467113032 rincgc 2.493819785 rincgc 2.480196911 rincgc 2.493542532 rincgc 2.494620295 ----------------------------------------------------------- loop_whileloop i = 0 while i<30_000_000 # benchmark loop 1 i += 1 end trunk 1.000023935 trunk 1.048546868 trunk 0.998132641 trunk 0.988056137 trunk 0.987234011 rincgc 0.999183002 rincgc 0.999639463 rincgc 0.966662006 rincgc 0.967072056 rincgc 0.998987652 ----------------------------------------------------------- loop_whileloop2 i = 0 while i< 6_000_000 # benchmark loop 2 i += 1 end trunk 0.246013766 trunk 0.294120293 trunk 0.243478716 trunk 0.244265345 trunk 0.24310837 rincgc 0.244274876 rincgc 0.251329509 rincgc 0.243869228 rincgc 0.250057863 rincgc 0.237723749 ----------------------------------------------------------- securerandom require "securerandom" 20_0000.times do SecureRandom.random_number(100) end trunk 1.763787748 trunk 1.745214895 trunk 1.770574136 trunk 1.762519029 trunk 1.739495001 rincgc 1.770725089 rincgc 1.748815865 rincgc 1.767314606 rincgc 1.758891782 rincgc 1.742911119 ----------------------------------------------------------- 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) trunk 1.321688302 trunk 1.263983625 trunk 1.41988183 trunk 1.27831435 trunk 1.278314858 rincgc 1.60885295 rincgc 1.694018528 rincgc 1.631627873 rincgc 1.6203333 rincgc 1.60811995 ----------------------------------------------------------- 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}" trunk 1.838965666 trunk 1.815903245 trunk 1.807792844 trunk 1.876013571 trunk 1.817143739 rincgc 2.1801557 rincgc 2.184377607 rincgc 2.177442727 rincgc 2.014257698 rincgc 2.23445984 ----------------------------------------------------------- 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 trunk 15.04287052 trunk 15.892497884 trunk 15.290912232 trunk 15.152038497 trunk 14.859203222 rincgc 15.776345735 rincgc 15.329596885 rincgc 15.701829136 rincgc 15.943962653 rincgc 15.857177822 ----------------------------------------------------------- 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 trunk 8.240776531 trunk 8.117082501 trunk 8.212853722 trunk 8.102906668 trunk 8.050121908 rincgc 7.992611835 rincgc 7.995092213 rincgc 8.012387984 rincgc 8.046655655 rincgc 8.045596507 ----------------------------------------------------------- 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}" trunk 0.465503344 trunk 0.468621011 trunk 0.466238387 trunk 0.467866021 trunk 0.466496564 rincgc 0.469478265 rincgc 0.466713562 rincgc 0.47079224 rincgc 0.466358639 rincgc 0.470352108 ----------------------------------------------------------- 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 trunk 0.830981704 trunk 0.823929705 trunk 0.815880407 trunk 0.828137928 trunk 0.811769549 rincgc 0.855266024 rincgc 0.846982156 rincgc 0.867582143 rincgc 0.851242395 rincgc 0.87925915 ----------------------------------------------------------- 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)}" trunk 3.297025868 trunk 3.293445336 trunk 3.309579381 trunk 3.339519033 trunk 3.368671407 rincgc 3.342083111 rincgc 3.327768243 rincgc 3.346495417 rincgc 3.362587256 rincgc 3.311929288 ----------------------------------------------------------- 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) trunk 4.584670689 trunk 4.45572989 trunk 4.31243219 trunk 4.383574364 trunk 4.497281214 rincgc 4.24283054 rincgc 4.277941184 rincgc 4.284257096 rincgc 4.264556325 rincgc 4.355747417 ----------------------------------------------------------- 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) } trunk 2.45789009 trunk 2.514874797 trunk 2.475645634 trunk 2.516639309 trunk 2.47265591 rincgc 2.491628477 rincgc 2.505712847 rincgc 2.564579864 rincgc 2.488421592 rincgc 2.552023755 ----------------------------------------------------------- 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 trunk 5.952742116 trunk 5.997617612 trunk 5.784756409 trunk 5.800729893 trunk 5.9261092 rincgc 6.044888441 rincgc 5.809976762 rincgc 5.927866699 rincgc 5.838754916 rincgc 6.015071325 ----------------------------------------------------------- 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]}" trunk 1.515944971 trunk 1.503394345 trunk 1.466925969 trunk 1.633348962 trunk 1.487597684 rincgc 1.462050091 rincgc 1.517853123 rincgc 1.480096568 rincgc 1.465132485 rincgc 1.612912627 ----------------------------------------------------------- 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!!! trunk 6.106963869 trunk 6.103061871 trunk 6.150901607 trunk 6.129659056 trunk 6.143248548 rincgc 6.232204534 rincgc 6.442438138 rincgc 6.377832718 rincgc 6.193215093 rincgc 6.291482908 ----------------------------------------------------------- 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) trunk 3.467570196 trunk 3.440936748 trunk 3.414076181 trunk 3.461988362 trunk 3.435151891 rincgc 3.61642921 rincgc 3.498640086 rincgc 3.564865163 rincgc 3.529918817 rincgc 3.572543811 ----------------------------------------------------------- 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 trunk 2.139823369 trunk 2.173843275 trunk 2.13817659 trunk 2.135076885 trunk 2.145310816 rincgc 2.147772749 rincgc 2.145384511 rincgc 2.145897327 rincgc 2.143670398 rincgc 2.146573294 ----------------------------------------------------------- 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 trunk 3.921055729 trunk 4.304466829 trunk 3.848458398 trunk 3.917863154 trunk 3.848098597 rincgc 3.674761699 rincgc 3.674669213 rincgc 3.686009556 rincgc 3.68032571 rincgc 3.657202247 ----------------------------------------------------------- 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 trunk 4.579325692 trunk 4.552972248 trunk 4.640411685 trunk 4.616691308 trunk 4.643850966 rincgc 4.796031253 rincgc 4.843048864 rincgc 4.771508955 rincgc 4.967992685 rincgc 4.764491785 ----------------------------------------------------------- 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 trunk 1.423339435 trunk 1.43077971 trunk 1.426829925 trunk 1.482807021 trunk 1.404641103 rincgc 1.505174323 rincgc 1.486103617 rincgc 1.568430755 rincgc 1.554817085 rincgc 1.544917683 ----------------------------------------------------------- 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 trunk 5.203980277 trunk 5.279681121 trunk 5.199831065 trunk 5.368561768 trunk 5.156826953 rincgc 5.17469631 rincgc 5.147302273 rincgc 5.261848525 rincgc 5.174080784 rincgc 5.150074746 ----------------------------------------------------------- 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 trunk 2.303561449 trunk 2.311473349 trunk 2.298235148 trunk 2.313707708 trunk 2.304731533 rincgc 2.265541831 rincgc 2.259600745 rincgc 2.267739273 rincgc 2.269045403 rincgc 2.258542837 ----------------------------------------------------------- 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) trunk 3.787728619 trunk 3.750983072 trunk 3.777855258 trunk 3.748010116 trunk 3.751950412 rincgc 3.993326338 rincgc 3.855666377 rincgc 3.997191136 rincgc 4.004241813 rincgc 3.845744977 ----------------------------------------------------------- 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 trunk 1.121652288 trunk 1.410924658 trunk 1.354646736 trunk 1.140282358 trunk 1.137394914 rincgc 1.148355325 rincgc 1.129524292 rincgc 1.111757276 rincgc 1.087919474 rincgc 1.150909079 ----------------------------------------------------------- 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 trunk 4.712320516 trunk 4.756388836 trunk 4.925920818 trunk 4.387982409 trunk 5.218160035 rincgc 3.994423372 rincgc 4.231192587 rincgc 4.437835611 rincgc 4.189417738 rincgc 4.144895343 ----------------------------------------------------------- vm1_array_append def foo ary = [] 100.times{|i| ary << i } end i=0 while i<300000 # while loop 1 i+=1 foo end trunk 4.939109477 trunk 4.538584847 trunk 4.323525208 trunk 4.331753483 trunk 4.362747977 rincgc 4.336079998 rincgc 4.691701715 rincgc 4.391938528 rincgc 4.331642754 rincgc 4.359666468 ----------------------------------------------------------- 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 trunk 3.975303046 trunk 3.969843267 trunk 3.970227886 trunk 3.969670247 trunk 4.48205764 rincgc 3.969754256 rincgc 3.970123809 rincgc 3.969305694 rincgc 3.970201308 rincgc 3.969638831 ----------------------------------------------------------- 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 trunk 4.523544308 trunk 4.420779266 trunk 4.519933283 trunk 4.409323075 trunk 4.405711853 rincgc 5.07881682 rincgc 4.676390027 rincgc 4.425331042 rincgc 4.420419829 rincgc 4.536102994 ----------------------------------------------------------- vm1_block def m yield end i = 0 while i<30_000_000 # while loop 1 i += 1 m{ } end trunk 4.841242378 trunk 4.866501232 trunk 5.477559743 trunk 4.359817092 trunk 4.564788375 rincgc 4.828692767 rincgc 4.866497988 rincgc 4.341403283 rincgc 5.343129683 rincgc 4.917849732 ----------------------------------------------------------- vm1_const Const = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = Const k = Const end trunk 2.097196261 trunk 2.110412899 trunk 1.562480868 trunk 1.562669597 trunk 1.55829289 rincgc 2.177859458 rincgc 3.125740624 rincgc 2.147534036 rincgc 2.147523577 rincgc 2.147472899 ----------------------------------------------------------- vm1_ensure i = 0 while i<30_000_000 # benchmark loop 1 i += 1 begin begin ensure end ensure end end trunk 1.245068042 trunk 1.244828979 trunk 1.244643257 trunk 1.244831194 trunk 1.244684145 rincgc 1.199740287 rincgc 1.199593251 rincgc 1.199518746 rincgc 1.199288523 rincgc 1.199530826 ----------------------------------------------------------- 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 trunk 10.605189021 trunk 10.540534783 trunk 10.714666115 trunk 10.692942662 trunk 10.547771111 rincgc 11.56902741 rincgc 10.596060951 rincgc 11.091298399 rincgc 11.099727442 rincgc 10.440128867 ----------------------------------------------------------- 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 trunk 21.826251222 trunk 22.150212237 trunk 24.019579044 trunk 24.229956195 trunk 22.482864318 rincgc 22.802899171 rincgc 23.099621088 rincgc 23.187241769 rincgc 22.85620851 rincgc 22.757397514 ----------------------------------------------------------- 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 trunk 26.571503531 trunk 26.319785922 trunk 28.617338188 trunk 28.443357488 trunk 28.412030536 rincgc 29.24987497 rincgc 27.929538822 rincgc 28.337448922 rincgc 28.506447601 rincgc 28.124570882 ----------------------------------------------------------- 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 trunk 25.577662907 trunk 26.438402692 trunk 25.756022602 trunk 25.486870111 trunk 26.037880338 rincgc 26.11849317 rincgc 26.316707265 rincgc 26.869514806 rincgc 26.448298625 rincgc 26.38980678 ----------------------------------------------------------- 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 trunk 23.620607171 trunk 23.413680647 trunk 23.650397943 trunk 24.195819461 trunk 23.478244183 rincgc 24.284171024 rincgc 25.651128215 rincgc 24.451593057 rincgc 24.113712267 rincgc 24.31504535 ----------------------------------------------------------- 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 trunk 2.37696381 trunk 2.49466307 trunk 2.37259383 trunk 2.815092131 trunk 3.06631125 rincgc 2.950702396 rincgc 2.959034413 rincgc 2.962048666 rincgc 2.922792394 rincgc 2.919293468 ----------------------------------------------------------- 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 trunk 2.161373789 trunk 2.16432018 trunk 2.689260929 trunk 2.095377002 trunk 2.182966945 rincgc 2.260757324 rincgc 2.829439619 rincgc 2.207967116 rincgc 2.819942335 rincgc 2.222196109 ----------------------------------------------------------- vm1_ivar @a = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = @a k = @a end trunk 2.843134752 trunk 2.841334076 trunk 2.844330552 trunk 2.844796249 trunk 2.844226703 rincgc 3.321929878 rincgc 2.960733042 rincgc 2.810284647 rincgc 2.852249071 rincgc 2.810144453 ----------------------------------------------------------- vm1_ivar_set i = 0 while i<30_000_000 # while loop 1 i += 1 @a = 1 @b = 2 end trunk 2.599943893 trunk 2.554819627 trunk 3.036225033 trunk 2.599798094 trunk 2.599650665 rincgc 3.141463292 rincgc 2.565510048 rincgc 2.569820895 rincgc 3.141308713 rincgc 2.554389276 ----------------------------------------------------------- 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 trunk 2.117738306 trunk 2.113149401 trunk 2.111423143 trunk 2.107395569 trunk 2.105825304 rincgc 2.087391683 rincgc 2.506039029 rincgc 2.099709192 rincgc 2.166494582 rincgc 2.810516031 ----------------------------------------------------------- vm1_length_original o = Object.new def o.length 0 end i=0 while i<30000000 # while loop 1 i+=1 o.length o.length end trunk 6.339698707 trunk 6.309967459 trunk 6.795438971 trunk 6.293330313 trunk 6.159118632 rincgc 6.804502042 rincgc 6.69703737 rincgc 6.855551971 rincgc 5.619247978 rincgc 5.702341166 ----------------------------------------------------------- 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 trunk 3.786249307 trunk 3.762226881 trunk 3.763302494 trunk 3.803611937 trunk 3.768847461 rincgc 3.820192012 rincgc 5.379948378 rincgc 3.78739499 rincgc 3.895642877 rincgc 4.321543909 ----------------------------------------------------------- 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 trunk 5.142809856 trunk 4.8719446 trunk 4.871751199 trunk 4.871940795 trunk 4.871845561 rincgc 5.03722517 rincgc 5.067072045 rincgc 5.593812553 rincgc 5.593874246 rincgc 5.067212224 ----------------------------------------------------------- vm1_neq i = 0 obj1 = Object.new obj2 = Object.new while i<30_000_000 # while loop 1 i += 1 obj1 != obj2 end trunk 2.039987303 trunk 2.069591893 trunk 2.018369826 trunk 2.650356344 trunk 2.250717037 rincgc 2.046863411 rincgc 2.069648802 rincgc 1.952400978 rincgc 2.621800908 rincgc 2.039007689 ----------------------------------------------------------- vm1_not i = 0 obj = Object.new while i<30_000_000 # while loop 1 i += 1 !obj end trunk 1.495162551 trunk 1.496622624 trunk 1.490579881 trunk 1.493590512 trunk 1.497012491 rincgc 1.450001239 rincgc 1.992016025 rincgc 1.452695084 rincgc 1.450307567 rincgc 1.445106613 ----------------------------------------------------------- vm1_rescue i = 0 while i<30_000_000 # while loop 1 i += 1 begin rescue end end trunk 1.690168227 trunk 1.692867608 trunk 1.245139826 trunk 1.247701814 trunk 1.244868497 rincgc 1.201001444 rincgc 1.207086101 rincgc 1.207126424 rincgc 1.207090163 rincgc 1.202153747 ----------------------------------------------------------- vm1_simplereturn def m return 1 end i = 0 while i<30_000_000 # while loop 1 i += 1 m end trunk 2.679575358 trunk 2.527509955 trunk 2.571918068 trunk 2.56155104 trunk 3.023225828 rincgc 2.585287072 rincgc 2.558413494 rincgc 3.253739629 rincgc 2.607783739 rincgc 2.718987734 ----------------------------------------------------------- vm1_swap a = 1 b = 2 i = 0 while i<30_000_000 # while loop 1 i += 1 a, b = b, a end trunk 1.473204296 trunk 1.47070876 trunk 1.473489436 trunk 1.471322015 trunk 1.469875176 rincgc 1.461994319 rincgc 1.472810003 rincgc 1.918162174 rincgc 1.934362208 rincgc 1.472244605 ----------------------------------------------------------- vm1_yield def m i = 0 while i<30_000_000 # while loop 1 i += 1 yield end end m{} trunk 2.853961742 trunk 2.743018899 trunk 2.844291675 trunk 2.842786805 trunk 2.8458508 rincgc 3.169004095 rincgc 2.825629973 rincgc 2.997599917 rincgc 3.389800803 rincgc 3.368811576 ----------------------------------------------------------- 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 trunk 2.386846756 trunk 2.37558179 trunk 2.366172142 trunk 2.374970996 trunk 2.383691127 rincgc 2.426212029 rincgc 2.39536557 rincgc 2.383831069 rincgc 2.40320399 rincgc 2.391360188 ----------------------------------------------------------- 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 trunk 21.855213756 trunk 21.733328902 trunk 21.876880968 trunk 21.700514329 trunk 21.74912824 rincgc 21.775019947 rincgc 21.838282461 rincgc 21.794925827 rincgc 21.870955286 rincgc 21.785370937 ----------------------------------------------------------- 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 trunk 13.993838499 trunk 14.057888763 trunk 13.832920229 trunk 14.135586745 trunk 13.871846689 rincgc 14.315452351 rincgc 14.399362675 rincgc 14.379683074 rincgc 14.33614826 rincgc 14.251247048 ----------------------------------------------------------- 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 trunk 0.60622392 trunk 0.594019219 trunk 0.586040323 trunk 0.712713177 trunk 0.711256468 rincgc 0.677305219 rincgc 0.680350853 rincgc 0.675753867 rincgc 0.680483137 rincgc 0.70351867 ----------------------------------------------------------- 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 trunk 6.647575915 trunk 7.07000666 trunk 7.01551139 trunk 6.682904821 trunk 6.614378226 rincgc 6.565305412 rincgc 6.67819251 rincgc 6.62468108 rincgc 6.634262334 rincgc 6.564703297 ----------------------------------------------------------- vm2_dstr i = 0 x = y = 'z' while i<6_000_000 # benchmark loop 2 i += 1 str = "foo#{x}bar#{y}baz" end trunk 3.212049257 trunk 3.178346402 trunk 3.16686685 trunk 3.180174745 trunk 3.151591797 rincgc 3.430022955 rincgc 3.452764831 rincgc 3.335309686 rincgc 3.223594833 rincgc 3.313856168 ----------------------------------------------------------- vm2_eval i = 0 while i<6_000_000 # benchmark loop 2 i += 1 eval("1") end trunk 53.538680777 trunk 53.097672982 trunk 53.371534252 trunk 53.949853162 trunk 53.195460152 rincgc 56.842159374 rincgc 56.172774916 rincgc 56.505905452 rincgc 56.108989408 rincgc 56.436519384 ----------------------------------------------------------- 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 trunk 3.033628629 trunk 4.007223743 trunk 2.915382409 trunk 2.962526422 trunk 2.921153113 rincgc 2.914626377 rincgc 3.45841393 rincgc 2.879997339 rincgc 2.868738694 rincgc 2.89434327 ----------------------------------------------------------- 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 trunk 5.383266159 trunk 4.657788545 trunk 4.633103675 trunk 4.579359993 trunk 5.053748999 rincgc 5.551555098 rincgc 5.289585892 rincgc 5.263824581 rincgc 5.440983609 rincgc 5.331396811 ----------------------------------------------------------- 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 trunk 3.224986119 trunk 3.330524173 trunk 3.234184045 trunk 3.287310485 trunk 3.366400846 rincgc 3.364288461 rincgc 3.352319866 rincgc 3.320480251 rincgc 4.112510734 rincgc 3.158749256 ----------------------------------------------------------- vm2_mutex require 'thread' m = Mutex.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m.synchronize{} end trunk 2.188572214 trunk 2.183431468 trunk 2.184159487 trunk 2.174098251 trunk 2.186493574 rincgc 2.157612144 rincgc 2.261122934 rincgc 2.142371103 rincgc 2.170065453 rincgc 2.148241739 ----------------------------------------------------------- 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 trunk 4.8064405 trunk 4.75306431 trunk 4.66834854 trunk 4.564208615 trunk 4.597964765 rincgc 5.174626347 rincgc 4.918099222 rincgc 5.402070374 rincgc 5.022267664 rincgc 4.925313474 ----------------------------------------------------------- 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 trunk 0.559061113 trunk 0.577581301 trunk 0.717402866 trunk 0.550188303 trunk 0.562875705 rincgc 0.653830564 rincgc 0.664261905 rincgc 0.686336475 rincgc 0.634505091 rincgc 0.62594781 ----------------------------------------------------------- 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 trunk 1.171415154 trunk 1.212670666 trunk 1.206882997 trunk 1.299603679 trunk 1.185986946 rincgc 1.214794745 rincgc 1.382000802 rincgc 1.204374546 rincgc 1.221594825 rincgc 1.22061038 ----------------------------------------------------------- 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 trunk 15.853113036 trunk 16.026980102 trunk 16.321502786 trunk 16.557524096 trunk 16.484618239 rincgc 16.912431209 rincgc 17.057152658 rincgc 17.171839132 rincgc 17.083530482 rincgc 16.981203186 ----------------------------------------------------------- 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 trunk 21.833238091 trunk 21.339271925 trunk 21.379255221 trunk 21.421551107 trunk 21.7710112 rincgc 22.130839319 rincgc 22.560104451 rincgc 22.337218944 rincgc 22.286786015 rincgc 21.777857516 ----------------------------------------------------------- vm2_regexp i = 0 str = 'xxxhogexxx' while i<6_000_000 # benchmark loop 2 /hoge/ =~ str i += 1 end trunk 2.771392206 trunk 2.583265117 trunk 2.58306791 trunk 2.580592494 trunk 2.597279203 rincgc 2.712158401 rincgc 2.709695742 rincgc 2.674999253 rincgc 2.665801341 rincgc 2.737509671 ----------------------------------------------------------- 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 trunk 0.845826047 trunk 0.860545997 trunk 0.859012877 trunk 0.877268203 trunk 0.856025942 rincgc 1.025650695 rincgc 0.883104696 rincgc 0.867280253 rincgc 1.000641573 rincgc 1.13844168 ----------------------------------------------------------- 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 trunk 1.085690507 trunk 1.090037189 trunk 1.168133573 trunk 1.1240085 trunk 1.141098197 rincgc 1.114996246 rincgc 1.06166298 rincgc 1.062304398 rincgc 1.249058718 rincgc 1.068750862 ----------------------------------------------------------- vm2_unif1 i = 0 def m a, b end while i<6_000_000 # benchmark loop 2 i += 1 m 100, 200 end trunk 0.582953317 trunk 0.589927197 trunk 0.577040501 trunk 0.57357104 trunk 0.608347182 rincgc 0.582841384 rincgc 0.600204148 rincgc 0.584957467 rincgc 0.810740958 rincgc 0.569292259 ----------------------------------------------------------- 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 trunk 1.127875235 trunk 1.189857418 trunk 1.139334326 trunk 1.124659172 trunk 1.122579676 rincgc 1.109050903 rincgc 1.112808671 rincgc 1.144851925 rincgc 1.175825225 rincgc 1.185304696 ----------------------------------------------------------- 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 trunk 0.419677533 trunk 0.418659192 trunk 0.420680418 trunk 0.41977798 trunk 0.421030665 rincgc 0.43753615 rincgc 0.436718364 rincgc 0.438928149 rincgc 0.438523605 rincgc 0.437748989 ----------------------------------------------------------- vm3_clearmethodcache i = 0 while i<200_000 i += 1 Class.new{ def m; end } end trunk 1.399278164 trunk 1.397031763 trunk 1.404965129 trunk 1.398081383 trunk 1.398789555 rincgc 1.419145972 rincgc 1.421869441 rincgc 1.423883335 rincgc 1.423319371 rincgc 1.428647024 ----------------------------------------------------------- vm3_gc #! /usr/bin/ruby 5000.times do 100.times do {"xxxx"=>"yyyy"} end GC.start end trunk 4.979860562 trunk 4.918548086 trunk 4.943984271 trunk 5.050776397 trunk 4.920926184 rincgc 5.135243098 rincgc 5.048921151 rincgc 5.186151721 rincgc 5.012400495 rincgc 5.17124235 ----------------------------------------------------------- vm3_thread_mutex exit require 'thread' m = Mutex.new r = 0 max = 1000 (1..max).map{ Thread.new{ i=0 while i