2014-08-03 23:12:04 +0000 target 0: trunk (ruby 2.2.0dev (2014-08-04 trunk 47049) [x86_64-linux]) at "i/bin/ruby" target 1: khash (ruby 2.2.0dev (2014-08-04 trunk 47049) [x86_64-linux]) at "./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.053466987 trunk 0.053458117 trunk 0.053313178 trunk 0.053252049 trunk 0.053146369 trunk 0.053039098 trunk 0.053222655 trunk 0.053343934 trunk 0.053211878 trunk 0.053716619 khash 0.05368008 khash 0.053426694 khash 0.053544113 khash 0.053474636 khash 0.054076212 khash 0.054618907 khash 0.053625231 khash 0.053436362 khash 0.053447513 khash 0.054776223 ----------------------------------------------------------- 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 45.189923735 trunk 42.21180712 trunk 42.777512279 trunk 43.172213134 trunk 45.4761473 trunk 42.293648305 trunk 42.512769743 trunk 44.720175456 trunk 43.053239425 trunk 42.967966857 khash 43.506109489 khash 43.069532791 khash 44.036169612 khash 43.706283231 khash 43.774789518 khash 46.72419823 khash 47.605560383 khash 46.965504914 khash 43.588814932 khash 43.37825325 ----------------------------------------------------------- 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 0.891688955 trunk 0.880409073 trunk 0.882336363 trunk 0.887284984 trunk 0.87945584 trunk 0.879002678 trunk 0.884034793 trunk 0.88556264 trunk 0.898553161 trunk 0.903378101 khash 0.874196717 khash 0.951727771 khash 0.897338582 khash 0.877491865 khash 0.870657513 khash 0.877496532 khash 0.867308061 khash 0.882250953 khash 0.873031234 khash 0.865114306 ----------------------------------------------------------- app_factorial def fact(n) if(n > 1) n * fact(n-1) else 1 end end 100.times { fact(5000) } trunk 0.780724817 trunk 0.785558255 trunk 0.745458472 trunk 0.786695664 trunk 0.787745932 trunk 0.758840613 trunk 0.787489071 trunk 0.782668415 trunk 0.784439264 trunk 0.796948316 khash 0.764969784 khash 0.788975773 khash 0.908709698 khash 0.776251314 khash 0.798474938 khash 0.778123113 khash 0.803207461 khash 0.794509895 khash 0.795727429 khash 0.775939638 ----------------------------------------------------------- app_fib def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(34) trunk 0.506633175 trunk 0.491960656 trunk 0.490122047 trunk 0.490980122 trunk 0.517056875 trunk 0.494596474 trunk 0.506380524 trunk 0.508552802 trunk 0.491268315 trunk 0.497149854 khash 0.476109802 khash 0.473895365 khash 0.477210612 khash 0.480293568 khash 0.471951312 khash 0.472067074 khash 0.503819841 khash 0.478625546 khash 0.490107434 khash 0.473757754 ----------------------------------------------------------- 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 0.934925131 trunk 0.900874666 trunk 0.950990032 trunk 0.904386171 trunk 0.904385768 trunk 0.951873712 trunk 0.930195927 trunk 0.912541319 trunk 0.909382528 trunk 0.908662135 khash 0.964173245 khash 0.920584212 khash 0.917550541 khash 0.995697854 khash 0.964008438 khash 0.917819085 khash 0.919938599 khash 0.915979709 khash 0.943913513 khash 1.006717303 ----------------------------------------------------------- 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 14.126628906 trunk 13.936032289 trunk 14.01563786 trunk 15.265776233 trunk 13.895848049 trunk 14.503810573 trunk 14.544154889 trunk 13.978188916 trunk 14.751462815 trunk 13.934834261 khash 13.942475949 khash 15.182030836 khash 13.990555176 khash 14.730465654 khash 14.756509168 khash 14.598895478 khash 14.55105026 khash 14.589816727 khash 14.985307495 khash 14.809483038 ----------------------------------------------------------- app_raise i = 0 while i<300000 i += 1 begin raise rescue end end trunk 0.262903898 trunk 0.260739437 trunk 0.348108011 trunk 0.278562747 trunk 0.259161537 trunk 0.259935039 trunk 0.260782529 trunk 0.271812478 trunk 0.259877682 trunk 0.260629122 khash 0.261967505 khash 0.265005507 khash 0.261496537 khash 0.261410328 khash 0.272931514 khash 0.261171853 khash 0.263947806 khash 0.260976841 khash 0.272272351 khash 0.260151937 ----------------------------------------------------------- app_strconcat i = 0 while i<2_000_000 "#{1+1} #{1+1} #{1+1}" i += 1 end trunk 0.933631388 trunk 0.928817588 trunk 0.934548833 trunk 0.931616116 trunk 0.943271169 trunk 0.934789727 trunk 0.929467261 trunk 0.937671417 trunk 0.931428967 trunk 0.928927454 khash 0.943962624 khash 0.958964862 khash 0.941419399 khash 0.933583586 khash 0.934031004 khash 0.934170399 khash 0.934747356 khash 0.949962502 khash 0.94182813 khash 0.936597506 ----------------------------------------------------------- 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 0.6848119 trunk 0.79158588 trunk 0.685060117 trunk 0.69278092 trunk 0.683866995 trunk 0.697930509 trunk 0.925633417 trunk 0.684767134 trunk 0.691800962 trunk 0.727177805 khash 0.752549903 khash 0.682482612 khash 0.897183819 khash 0.774532937 khash 0.860372567 khash 0.826266938 khash 0.863369094 khash 0.762379525 khash 0.701596608 khash 0.775156217 ----------------------------------------------------------- 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 0.562808763 trunk 0.559980262 trunk 0.600481972 trunk 0.610727997 trunk 0.55831145 trunk 0.559962857 trunk 0.563216845 trunk 0.576789014 trunk 0.552515042 trunk 0.566037874 khash 0.573687579 khash 0.55340991 khash 0.575610803 khash 0.558030448 khash 0.554167157 khash 0.5552617 khash 0.552153026 khash 0.562136274 khash 0.553098873 khash 0.554434499 ----------------------------------------------------------- app_uri require 'uri' 100_000.times{ uri = URI.parse('http://www.ruby-lang.org') uri.scheme uri.host uri.port } trunk 0.66480812 trunk 0.67451507 trunk 0.667587624 trunk 0.672607456 trunk 0.668937404 trunk 0.673203553 trunk 0.670374489 trunk 0.666820092 trunk 0.678419927 trunk 0.867198241 khash 0.662282341 khash 0.663924205 khash 0.656278158 khash 0.67338241 khash 0.653004079 khash 0.662283144 khash 0.661670626 khash 0.684524696 khash 0.667858573 khash 0.666529919 ----------------------------------------------------------- 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 0.464507562 trunk 0.464419008 trunk 0.522312019 trunk 0.46339518 trunk 0.451500395 trunk 0.474404979 trunk 0.462190242 trunk 0.464740958 trunk 0.459908201 trunk 0.456807409 khash 0.479056491 khash 0.456972612 khash 0.460964646 khash 0.541477651 khash 0.445830827 khash 0.5409136 khash 0.557045443 khash 0.535141198 khash 0.484410566 khash 0.465003459 ----------------------------------------------------------- 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 0.423633592 trunk 0.507854557 trunk 0.460481618 trunk 0.42021069 trunk 0.455372786 trunk 0.461124237 trunk 0.42732133 trunk 0.430708278 trunk 0.652576004 trunk 0.43087096 khash 0.495004969 khash 0.52045349 khash 0.41869569 khash 0.450764779 khash 0.418237039 khash 0.615931213 khash 0.418195364 khash 0.41469595 khash 0.420895375 khash 0.414948301 ----------------------------------------------------------- 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 0.611950592 trunk 0.602765962 trunk 0.606608662 trunk 0.614288494 trunk 0.61136069 trunk 0.617507317 trunk 0.611570628 trunk 0.60473123 trunk 0.598150097 trunk 0.610474888 khash 0.597648061 khash 0.605671894 khash 0.605628843 khash 0.607148277 khash 0.606094567 khash 0.606846892 khash 0.604287492 khash 0.603902097 khash 0.604940445 khash 0.602041399 ----------------------------------------------------------- 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 1.420842125 trunk 1.428072927 trunk 1.513315889 trunk 1.439968614 trunk 1.430021572 trunk 1.691212726 trunk 1.4211402 trunk 1.419501573 trunk 1.425089996 trunk 1.426886991 khash 1.430935604 khash 1.599584803 khash 1.43166371 khash 1.572183007 khash 1.463556025 khash 1.630858369 khash 1.496293448 khash 1.754545845 khash 1.431028248 khash 1.451544393 ----------------------------------------------------------- hash_flatten h = {} 10000.times do |i| h[i] = nil end 1000.times do h.flatten end trunk 0.396782675 trunk 0.392580817 trunk 0.398748991 trunk 0.393970503 trunk 0.397382055 trunk 0.398349684 trunk 0.396269936 trunk 0.402481318 trunk 0.395438661 trunk 0.39806857 khash 0.406777622 khash 0.39511308 khash 0.39773928 khash 0.395086737 khash 0.394637777 khash 0.394499537 khash 0.393939171 khash 0.399003257 khash 0.393808143 khash 0.393965775 ----------------------------------------------------------- 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.293703003 trunk 0.300416573 trunk 0.300583671 trunk 0.292729413 trunk 0.301533728 trunk 0.300641136 trunk 0.302150064 trunk 0.292693464 trunk 0.299458865 trunk 0.293632262 khash 0.301977339 khash 0.301098561 khash 0.294490872 khash 0.293127073 khash 0.299863481 khash 0.29203186 khash 0.293736013 khash 0.293193016 khash 0.297143108 khash 0.29307632 ----------------------------------------------------------- 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.300609502 trunk 0.288940539 trunk 0.288389151 trunk 0.299989446 trunk 0.293119505 trunk 0.288889066 trunk 0.294691708 trunk 0.294920099 trunk 0.298019499 trunk 0.288721793 khash 0.298664342 khash 0.290775825 khash 0.289791303 khash 0.296553527 khash 0.292516056 khash 0.290045061 khash 0.300873571 khash 0.289622269 khash 0.300112981 khash 0.289628587 ----------------------------------------------------------- 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.297504864 trunk 0.29155858 trunk 0.29364117 trunk 0.291276798 trunk 0.290916835 trunk 0.288079248 trunk 0.292609349 trunk 0.288409805 trunk 0.296402648 trunk 0.290939747 khash 0.36990586 khash 0.372296983 khash 0.29943807 khash 0.30065575 khash 0.294766323 khash 0.307524477 khash 0.377024517 khash 0.299863752 khash 0.294475602 khash 0.302802747 ----------------------------------------------------------- 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.336592683 trunk 0.389864328 trunk 0.351896003 trunk 0.309709136 trunk 0.314823655 trunk 0.339615124 trunk 0.329608466 trunk 0.420753215 trunk 0.332809712 trunk 0.409397895 khash 0.329861586 khash 0.33945197 khash 0.336797117 khash 0.393150382 khash 0.357284995 khash 0.353211263 khash 0.391730543 khash 0.453081644 khash 0.333151586 khash 0.315552214 ----------------------------------------------------------- hash_keys h = {} 10000.times do |i| h[i] = nil end 5000.times do h.keys end trunk 0.233805262 trunk 0.234791078 trunk 0.235693474 trunk 0.235769542 trunk 0.2351856 trunk 0.236100032 trunk 0.234829111 trunk 0.234380966 trunk 0.234725121 trunk 0.2347109 khash 0.233367024 khash 0.232822283 khash 0.234393943 khash 0.234515393 khash 0.233329725 khash 0.234324514 khash 0.233167409 khash 0.235867448 khash 0.233305151 khash 0.233064962 ----------------------------------------------------------- hash_shift h = {} 10000.times do |i| h[i] = nil end 50000.times do k, v = h.shift h[k] = v end trunk 0.037960301 trunk 0.036479244 trunk 0.036616403 trunk 0.036611706 trunk 0.036603661 trunk 0.036613574 trunk 0.037598764 trunk 0.037653 trunk 0.036685957 trunk 0.036665733 khash 0.038205669 khash 0.037794626 khash 0.037741385 khash 0.037713927 khash 0.036712517 khash 0.037814223 khash 0.036816318 khash 0.037026347 khash 0.037915542 khash 0.03686534 ----------------------------------------------------------- hash_values h = {} 10000.times do |i| h[i] = nil end 5000.times do h.values end trunk 0.244861282 trunk 0.244467328 trunk 0.24491896 trunk 0.243777616 trunk 0.245172426 trunk 0.24554915 trunk 0.244490455 trunk 0.244269237 trunk 0.245211082 trunk 0.245816055 khash 0.24536108 khash 0.244845285 khash 0.244868963 khash 0.243828867 khash 0.245541516 khash 0.244221705 khash 0.245297242 khash 0.244710736 khash 0.244009321 khash 0.244569462 ----------------------------------------------------------- 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 1.201332535 trunk 1.211590856 trunk 1.241850564 trunk 1.232180325 trunk 1.242059011 trunk 1.12506797 trunk 1.167083756 trunk 1.150376355 trunk 1.187526342 trunk 1.258680961 khash 1.189778532 khash 1.11575173 khash 1.289642586 khash 1.1580251 khash 1.303446114 khash 1.318548298 khash 1.226493673 khash 1.175413588 khash 1.174568668 khash 1.186631132 ----------------------------------------------------------- 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 1.348127492 trunk 1.182065475 trunk 1.259706698 trunk 1.171748649 trunk 1.282594346 trunk 1.295878193 trunk 1.127686635 trunk 1.290889324 trunk 1.290417602 trunk 1.135683614 khash 1.137797915 khash 1.137477126 khash 1.111005332 khash 1.104575883 khash 1.132862047 khash 1.175004599 khash 1.113976038 khash 1.10443849 khash 1.180374683 khash 1.251582035 ----------------------------------------------------------- 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 0.824914681 trunk 0.819273072 trunk 0.777330835 trunk 0.865865769 trunk 0.774154481 trunk 0.76629453 trunk 0.781981921 trunk 0.807762027 trunk 0.768558504 trunk 0.794430856 khash 0.924810447 khash 0.81788601 khash 0.768963324 khash 0.766767844 khash 0.768651354 khash 0.775799549 khash 0.780248781 khash 0.80516594 khash 0.838577004 khash 0.845469352 ----------------------------------------------------------- io_select # IO.select performance w = [ IO.pipe[1] ]; nr = 1000000 nr.times { IO.select nil, w } trunk 1.363281604 trunk 1.572922046 trunk 1.368199318 trunk 1.483722364 trunk 1.64713751 trunk 1.436825332 trunk 1.448129372 trunk 1.437168265 trunk 1.405375314 trunk 1.32296261 khash 1.323508663 khash 1.3240622 khash 1.335771481 khash 1.375261479 khash 1.371871102 khash 1.326905927 khash 1.32244163 khash 1.326290439 khash 1.325629905 khash 1.32270435 ----------------------------------------------------------- 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 1.500501706 trunk 1.490072128 trunk 1.473657198 trunk 1.475678383 trunk 1.468837491 trunk 1.473806075 trunk 1.75361907 trunk 1.493110428 trunk 1.553615565 trunk 1.503963082 khash 1.518147916 khash 1.657041162 khash 1.709747497 khash 1.648019677 khash 1.546448892 khash 1.480331057 khash 1.492363943 khash 1.481867412 khash 1.489455113 khash 1.479758717 ----------------------------------------------------------- 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.033969406 trunk 0.033843398 trunk 0.033817264 trunk 0.033898229 trunk 0.033757124 trunk 0.033849442 trunk 0.033721226 trunk 0.033974411 trunk 0.033719697 trunk 0.033803306 khash 0.033852152 khash 0.034342393 khash 0.034004278 khash 0.034085064 khash 0.034488998 khash 0.033954845 khash 0.034097229 khash 0.034191642 khash 0.034148014 khash 0.033985463 ----------------------------------------------------------- loop_for for i in 1..30_000_000 # end trunk 1.113344189 trunk 1.108065128 trunk 1.090690749 trunk 1.094765732 trunk 1.139520606 trunk 1.090629685 trunk 1.092442487 trunk 1.161253292 trunk 1.09068213 trunk 1.10605635 khash 1.119402424 khash 1.093976798 khash 1.125691256 khash 1.104400715 khash 1.10257755 khash 1.172074032 khash 1.11114226 khash 1.093504229 khash 1.207964288 khash 1.205482147 ----------------------------------------------------------- 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 0.68171001 trunk 0.667249909 trunk 0.671614983 trunk 0.683071763 trunk 0.677607948 trunk 0.671950347 trunk 0.72192379 trunk 0.667579254 trunk 0.738809836 trunk 0.701274972 khash 0.698951463 khash 0.819079049 khash 0.683086994 khash 0.663267754 khash 0.66380817 khash 0.671936358 khash 0.675173102 khash 0.662424519 khash 0.66809848 khash 0.666806707 ----------------------------------------------------------- loop_times 30_000_000.times{|e|} trunk 1.075514729 trunk 1.100153512 trunk 1.022955917 trunk 1.023028437 trunk 1.058340095 trunk 1.023271617 trunk 1.021956868 trunk 1.023321095 trunk 1.025093406 trunk 1.074479654 khash 1.053706509 khash 1.045124542 khash 1.022166659 khash 1.090937937 khash 1.034938274 khash 1.057010665 khash 1.046004661 khash 1.024092924 khash 1.034713939 khash 1.120905565 ----------------------------------------------------------- loop_whileloop i = 0 while i<30_000_000 # benchmark loop 1 i += 1 end trunk 0.509002 trunk 0.508979294 trunk 0.509540823 trunk 0.508948596 trunk 0.510198709 trunk 0.509134539 trunk 0.509442758 trunk 0.522111912 trunk 0.523698042 trunk 0.522344128 khash 0.513496466 khash 0.510155586 khash 0.516673152 khash 0.504261361 khash 0.609433056 khash 0.529473307 khash 0.602362184 khash 0.561036854 khash 0.552961657 khash 0.519367427 ----------------------------------------------------------- loop_whileloop2 i = 0 while i< 6_000_000 # benchmark loop 2 i += 1 end trunk 0.117931277 trunk 0.117949368 trunk 0.118731252 trunk 0.118595869 trunk 0.117916663 trunk 0.117577206 trunk 0.128639508 trunk 0.117786957 trunk 0.120455277 trunk 0.118106643 khash 0.118527271 khash 0.118007698 khash 0.122495193 khash 0.118142398 khash 0.126653252 khash 0.118106617 khash 0.118524476 khash 0.118291989 khash 0.118980043 khash 0.118390311 ----------------------------------------------------------- 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 0.614802211 trunk 0.570043348 trunk 0.555605973 trunk 0.562890083 trunk 0.554898748 trunk 0.555493317 trunk 0.558574593 trunk 0.554531301 trunk 0.554539737 trunk 0.555235133 khash 0.554917114 khash 0.555491841 khash 0.555667664 khash 0.557166574 khash 0.556229754 khash 0.555149683 khash 0.55759257 khash 0.556182683 khash 0.569055659 khash 0.554954032 ----------------------------------------------------------- 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 0.758799758 trunk 0.757487239 trunk 0.758487862 trunk 0.75741912 trunk 0.772861922 trunk 0.757461785 trunk 0.757551162 trunk 0.759251176 trunk 0.760249007 trunk 0.774246875 khash 0.767555257 khash 0.75425686 khash 0.756679014 khash 0.760836547 khash 0.753024356 khash 0.75408857 khash 0.75611852 khash 0.754468772 khash 0.756497275 khash 0.754725784 ----------------------------------------------------------- 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 6.614047743 trunk 5.844373953 trunk 5.765137014 trunk 5.778627731 trunk 5.712070856 trunk 5.722393349 trunk 5.718119361 trunk 5.832878194 trunk 5.717109029 trunk 5.809554618 khash 5.797741071 khash 5.73446621 khash 5.767491216 khash 5.815418334 khash 5.867731666 khash 5.920038736 khash 5.770153777 khash 5.780037583 khash 5.765090116 khash 5.783361295 ----------------------------------------------------------- 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 3.212220865 trunk 3.171628025 trunk 3.552582604 trunk 3.639366616 trunk 4.68131874 trunk 3.52789021 trunk 4.011574121 trunk 3.618311289 trunk 3.500272133 trunk 3.156485512 khash 3.294912745 khash 3.194320855 khash 3.259327142 khash 3.195611365 khash 3.195185155 khash 3.192356902 khash 3.190380733 khash 3.678810887 khash 3.847466629 khash 4.076291399 ----------------------------------------------------------- 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.19529061 trunk 0.19525172 trunk 0.195523418 trunk 0.195121858 trunk 0.195229457 trunk 0.195310306 trunk 0.194867535 trunk 0.195133233 trunk 0.195662451 trunk 0.195269353 khash 0.238799625 khash 0.237449168 khash 0.221210209 khash 0.220920282 khash 0.235217146 khash 0.208920425 khash 0.23283025 khash 0.22563123 khash 0.234247895 khash 0.22957157 ----------------------------------------------------------- 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.255487029 trunk 0.268093882 trunk 0.254850814 trunk 0.253474376 trunk 0.254617996 trunk 0.254884716 trunk 0.253574228 trunk 0.253060733 trunk 0.254192999 trunk 0.268406355 khash 0.255352319 khash 0.263985612 khash 0.254131276 khash 0.258399013 khash 0.256693753 khash 0.254457613 khash 0.267330758 khash 0.256218993 khash 0.257373574 khash 0.276135691 ----------------------------------------------------------- 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 0.985111607 trunk 1.008532231 trunk 0.991028894 trunk 0.998439485 trunk 0.985825972 trunk 1.026226374 trunk 0.996490468 trunk 0.987434909 trunk 0.989058114 trunk 1.001241814 khash 1.001596007 khash 0.994865033 khash 1.001635634 khash 1.014822335 khash 0.998381892 khash 0.993861879 khash 0.994297374 khash 1.014268487 khash 0.988747137 khash 0.997169933 ----------------------------------------------------------- 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 1.640717066 trunk 1.642615927 trunk 1.603085537 trunk 1.627394153 trunk 1.605785237 trunk 1.638631179 trunk 1.677683908 trunk 1.648724504 trunk 1.602648408 trunk 1.629091812 khash 1.621446004 khash 1.6582663 khash 1.656775754 khash 1.64068221 khash 1.623386249 khash 1.621988795 khash 1.615638005 khash 1.618054854 khash 1.650524842 khash 1.626123076 ----------------------------------------------------------- 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 1.0102157 trunk 1.052557545 trunk 1.012677957 trunk 1.043044123 trunk 1.014355928 trunk 1.036236439 trunk 1.015913398 trunk 1.016970986 trunk 1.036649461 trunk 1.018479169 khash 1.025950544 khash 1.019982691 khash 1.041912633 khash 1.024627823 khash 1.023429118 khash 1.026261433 khash 1.020031486 khash 1.035860033 khash 1.022377027 khash 1.049025149 ----------------------------------------------------------- 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 2.011732872 trunk 2.045652032 trunk 2.012346034 trunk 2.11214165 trunk 2.072024145 trunk 2.045823551 trunk 2.014632922 trunk 2.011002574 trunk 2.017385323 trunk 2.010717924 khash 2.153930493 khash 2.062775788 khash 2.056019856 khash 2.087093122 khash 2.130075555 khash 2.207385256 khash 2.144220318 khash 2.091765263 khash 2.080823269 khash 2.109802141 ----------------------------------------------------------- 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 0.503951844 trunk 0.50537105 trunk 0.503110194 trunk 0.529639026 trunk 0.502648582 trunk 0.538807233 trunk 0.515061425 trunk 0.503707823 trunk 0.50835968 trunk 0.502084719 khash 0.504558125 khash 0.528462271 khash 0.504499108 khash 0.535119883 khash 0.514428354 khash 0.508404499 khash 0.501950324 khash 0.512967709 khash 0.525623559 khash 0.519225174 ----------------------------------------------------------- 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 2.66239131 trunk 2.695473377 trunk 2.700787826 trunk 2.678963339 trunk 2.694777505 trunk 2.669607851 trunk 2.714917931 trunk 2.697084359 trunk 2.736961824 trunk 2.741664884 khash 2.703699321 khash 2.695845142 khash 2.678990937 khash 2.686205004 khash 2.66388862 khash 2.680025513 khash 2.647667828 khash 2.656589783 khash 2.666075901 khash 2.687602495 ----------------------------------------------------------- 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 1.157146009 trunk 1.16346001 trunk 1.227089087 trunk 1.164163868 trunk 1.220961624 trunk 1.168000907 trunk 1.495992887 trunk 1.209057533 trunk 1.341749367 trunk 1.649214319 khash 1.51294175 khash 1.622124164 khash 1.171958631 khash 1.175508763 khash 1.287121597 khash 1.172287075 khash 1.192836256 khash 1.17418644 khash 1.226366169 khash 1.173000081 ----------------------------------------------------------- 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 0.963365491 trunk 0.923841424 trunk 0.923377859 trunk 0.952866959 trunk 0.93679848 trunk 0.925483993 trunk 0.924076271 trunk 0.930777424 trunk 0.944655759 trunk 0.925374742 khash 0.949026925 khash 0.930576495 khash 0.930285646 khash 0.930293532 khash 0.929535122 khash 1.191714183 khash 0.948895089 khash 0.937198758 khash 0.931118947 khash 1.074536408 ----------------------------------------------------------- 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 1.53126005 trunk 1.471442638 trunk 1.469284757 trunk 1.618282607 trunk 1.48084218 trunk 1.489923911 trunk 1.454834248 trunk 1.459916558 trunk 1.479716944 trunk 1.462779308 khash 1.455654166 khash 1.452947864 khash 1.460217594 khash 1.451927253 khash 1.459694048 khash 1.456046495 khash 1.454958001 khash 1.462466051 khash 1.459652556 khash 1.496713509 ----------------------------------------------------------- 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 1.997177927 trunk 2.080370601 trunk 1.957162512 trunk 1.948983627 trunk 2.04259568 trunk 2.555866435 trunk 2.178742358 trunk 2.601944285 trunk 2.712019012 trunk 3.493152529 khash 2.07549786 khash 2.106493779 khash 1.983208136 khash 2.075573702 khash 2.073005797 khash 2.495238228 khash 1.985144173 khash 2.013594836 khash 1.985015894 khash 2.083381728 ----------------------------------------------------------- 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 0.59102741 trunk 0.588617024 trunk 0.587933364 trunk 0.58777413 trunk 0.589195404 trunk 0.589072983 trunk 0.588269759 trunk 0.59137852 trunk 0.59108711 trunk 0.591874707 khash 0.619423305 khash 0.626843473 khash 0.600053908 khash 0.669724755 khash 0.600431841 khash 0.598908208 khash 0.614328507 khash 0.607087826 khash 0.682891696 khash 0.752149928 ----------------------------------------------------------- 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 1.874247287 trunk 2.307670915 trunk 1.764508378 trunk 2.142871131 trunk 1.765606801 trunk 1.762215151 trunk 1.761762692 trunk 1.760612168 trunk 1.767315719 trunk 1.772674695 khash 1.773843961 khash 1.779236697 khash 1.782912176 khash 1.788741324 khash 1.816863757 khash 1.768716976 khash 1.780141429 khash 1.771651142 khash 1.869815 khash 1.776112597 ----------------------------------------------------------- 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 0.951768955 trunk 0.951453795 trunk 0.952732947 trunk 0.950151459 trunk 0.951862284 trunk 1.013215685 trunk 0.948446398 trunk 0.947965488 trunk 0.945072271 trunk 0.947166412 khash 0.945507295 khash 0.948509895 khash 0.946134392 khash 0.948116514 khash 0.950740529 khash 0.947332245 khash 1.017866695 khash 0.944319698 khash 0.942301908 khash 0.949187656 ----------------------------------------------------------- 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 1.076037848 trunk 1.080914692 trunk 1.077727345 trunk 1.076734623 trunk 1.127595187 trunk 1.078844332 trunk 1.073735695 trunk 1.075504509 trunk 1.075485207 trunk 1.079442072 khash 1.073437319 khash 1.162261714 khash 1.079562478 khash 1.073668936 khash 1.071285535 khash 1.144733524 khash 1.081704456 khash 1.086805937 khash 1.076574396 khash 1.077368392 ----------------------------------------------------------- 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 0.469153505 trunk 0.469947187 trunk 0.552376783 trunk 0.46967338 trunk 0.475872563 trunk 0.469837136 trunk 0.46922022 trunk 0.469837141 trunk 0.469817931 trunk 0.469642016 khash 0.469524235 khash 0.469868731 khash 0.594418949 khash 0.46992944 khash 0.46987094 khash 0.46953837 khash 0.599272446 khash 0.469811209 khash 0.590944639 khash 0.469799425 ----------------------------------------------------------- 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 1.77021718 trunk 1.840168309 trunk 1.758788004 trunk 1.759587233 trunk 1.935635161 trunk 1.759166546 trunk 1.758848111 trunk 1.760140443 trunk 1.758478901 trunk 1.782560855 khash 1.754959918 khash 2.089403106 khash 1.756361396 khash 2.106910424 khash 2.01638943 khash 2.157113879 khash 1.76093081 khash 1.785258748 khash 1.822789451 khash 1.755311257 ----------------------------------------------------------- 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 1.335312008 trunk 1.076701782 trunk 1.081983139 trunk 1.09884679 trunk 1.078074989 trunk 1.077457679 trunk 1.191746972 trunk 1.077512266 trunk 1.076646777 trunk 1.189342262 khash 1.078546794 khash 1.082987079 khash 1.077015132 khash 1.077067572 khash 1.189575111 khash 1.07940583 khash 1.188131558 khash 1.085289357 khash 1.076762646 khash 1.077376092 ----------------------------------------------------------- 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 1.347835506 trunk 1.320812787 trunk 1.377261016 trunk 1.968581468 trunk 1.321402453 trunk 1.372078229 trunk 1.597772193 trunk 1.302064135 trunk 1.299650999 trunk 1.299206473 khash 1.299896154 khash 1.363747867 khash 1.326938688 khash 1.297643392 khash 1.357253607 khash 1.316292888 khash 1.313003929 khash 1.296722329 khash 1.307895893 khash 1.319161891 ----------------------------------------------------------- vm1_block def m yield end i = 0 while i<30_000_000 # while loop 1 i += 1 m{ } end trunk 1.998536945 trunk 1.990157578 trunk 2.322986081 trunk 2.010165436 trunk 3.200956702 trunk 2.176548629 trunk 2.202746491 trunk 2.83597393 trunk 2.288945902 trunk 2.73453375 khash 1.996904752 khash 1.996486824 khash 1.996878944 khash 2.030366552 khash 2.009328555 khash 1.999080265 khash 2.130948712 khash 2.087991076 khash 2.065977623 khash 1.996519476 ----------------------------------------------------------- vm1_const Const = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = Const k = Const end trunk 0.729250469 trunk 0.775314424 trunk 0.72961093 trunk 0.728960512 trunk 0.728953167 trunk 0.729346967 trunk 0.728171793 trunk 0.728974337 trunk 0.728880025 trunk 0.728868298 khash 0.72941772 khash 0.745163273 khash 0.812847538 khash 0.744922567 khash 0.73040355 khash 0.742839314 khash 0.733286995 khash 0.926057867 khash 0.888328012 khash 0.795108024 ----------------------------------------------------------- vm1_ensure i = 0 while i<30_000_000 # benchmark loop 1 i += 1 begin begin ensure end ensure end end trunk 0.515718649 trunk 0.510670857 trunk 0.575808312 trunk 0.517685105 trunk 0.605871381 trunk 0.68333744 trunk 0.517571953 trunk 0.509947585 trunk 0.509867777 trunk 0.5103289 khash 0.510404637 khash 0.509785532 khash 0.510305504 khash 0.510247163 khash 0.510331683 khash 0.510362989 khash 0.51026988 khash 0.510280153 khash 0.516982537 khash 0.584822726 ----------------------------------------------------------- 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 4.275642812 trunk 4.17730526 trunk 4.24303098 trunk 4.210518574 trunk 4.118644585 trunk 4.544811915 trunk 6.526726663 trunk 4.517240112 trunk 4.243415033 trunk 4.208912234 khash 4.305312794 khash 4.260770963 khash 4.650174236 khash 4.850609153 khash 5.268925497 khash 5.557708186 khash 4.249503263 khash 4.280380865 khash 4.2721043 khash 5.014142668 ----------------------------------------------------------- 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 9.53106247 trunk 9.660719527 trunk 9.61664472 trunk 8.987084288 trunk 8.93446428 trunk 9.567102899 trunk 9.985327853 trunk 8.960408697 trunk 9.003664314 trunk 9.134594279 khash 9.086436344 khash 8.96494725 khash 9.50599771 khash 8.961402921 khash 10.095026488 khash 9.367787848 khash 9.181634361 khash 8.983986737 khash 10.024024868 khash 9.817934961 ----------------------------------------------------------- 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 10.684484183 trunk 10.725419742 trunk 10.706030559 trunk 10.780098474 trunk 10.869648129 trunk 10.725552716 trunk 10.769441936 trunk 10.650478136 trunk 10.737586048 trunk 11.040341402 khash 12.126285503 khash 10.694920611 khash 10.685271612 khash 10.776132233 khash 10.735951768 khash 10.278400675 khash 10.703388334 khash 10.781115205 khash 11.000338249 khash 10.826203957 ----------------------------------------------------------- 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 10.266887099 trunk 10.256498409 trunk 11.518806822 trunk 10.07181952 trunk 9.707568153 trunk 9.844087485 trunk 9.787667486 trunk 10.147147225 trunk 9.945830235 trunk 9.87086131 khash 9.786441769 khash 9.872680098 khash 10.799366234 khash 9.81202494 khash 10.018574411 khash 9.779913443 khash 9.747222161 khash 10.009774005 khash 9.832541582 khash 9.772140039 ----------------------------------------------------------- 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 9.316251409 trunk 9.188900632 trunk 9.632393746 trunk 9.959116235 trunk 9.323491386 trunk 9.555212744 trunk 9.569080756 trunk 10.357845525 trunk 9.352633119 trunk 9.436430834 khash 9.326024889 khash 10.32599116 khash 9.746250403 khash 9.366021559 khash 9.47478462 khash 9.658505344 khash 10.195050742 khash 9.561546884 khash 9.360751861 khash 9.372649134 ----------------------------------------------------------- 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 1.099199695 trunk 1.072971813 trunk 1.132074033 trunk 1.480313867 trunk 1.36479202 trunk 1.018684806 trunk 1.016564206 trunk 1.133407308 trunk 1.104613691 trunk 1.328363286 khash 1.016978596 khash 1.019468944 khash 1.016812547 khash 1.01656933 khash 1.016614268 khash 1.016937831 khash 1.019132462 khash 1.196342178 khash 1.016720564 khash 1.016748108 ----------------------------------------------------------- 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 0.995784059 trunk 0.992377818 trunk 0.978695824 trunk 0.975698994 trunk 1.04074008 trunk 0.975826152 trunk 1.339764016 trunk 0.976402537 trunk 1.001545392 trunk 0.976375777 khash 0.97695287 khash 0.982227077 khash 0.976993943 khash 0.977549961 khash 0.976938869 khash 0.976530342 khash 0.976999782 khash 0.976739069 khash 0.977598933 khash 1.110521374 ----------------------------------------------------------- vm1_ivar @a = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = @a k = @a end trunk 0.979027708 trunk 0.746354584 trunk 0.832513661 trunk 0.796542857 trunk 0.755649176 trunk 1.028289876 trunk 0.751095581 trunk 0.814685161 trunk 0.734287026 trunk 0.946313345 khash 0.732663602 khash 0.769132132 khash 0.819902048 khash 0.73238115 khash 0.732208039 khash 0.732415281 khash 0.732230561 khash 0.732243121 khash 0.732193854 khash 0.732182412 ----------------------------------------------------------- vm1_ivar_set i = 0 while i<30_000_000 # while loop 1 i += 1 @a = 1 @b = 2 end trunk 0.78959295 trunk 0.806741829 trunk 0.80727015 trunk 0.78944366 trunk 0.789357774 trunk 0.789360877 trunk 0.789858355 trunk 0.791063431 trunk 1.043550748 trunk 0.791129544 khash 0.796408292 khash 0.931205085 khash 0.796079573 khash 0.795882013 khash 0.841121268 khash 0.902178694 khash 0.88137258 khash 0.801897923 khash 0.796013087 khash 0.796276222 ----------------------------------------------------------- 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 0.928041672 trunk 0.928007856 trunk 0.927905602 trunk 0.928012097 trunk 0.927921115 trunk 0.927895556 trunk 0.927909023 trunk 1.019171958 trunk 0.92803847 trunk 1.021568363 khash 1.152198143 khash 1.05775043 khash 1.040012105 khash 1.00595545 khash 1.057697881 khash 0.928889992 khash 0.928389708 khash 0.960841663 khash 0.964275057 khash 0.971162504 ----------------------------------------------------------- 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 1.846739715 trunk 1.71139141 trunk 1.70810237 trunk 1.702212664 trunk 1.830586724 trunk 1.703026407 trunk 1.700068627 trunk 1.700212589 trunk 1.710938758 trunk 1.7076475 khash 1.698763249 khash 1.707127308 khash 1.698297234 khash 1.758391482 khash 1.700924106 khash 1.711788663 khash 1.721121203 khash 1.700457405 khash 2.041361147 khash 1.727172391 ----------------------------------------------------------- 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 2.545387105 trunk 2.476221461 trunk 2.533390554 trunk 2.504763867 trunk 2.474219479 trunk 2.475366956 trunk 2.47537071 trunk 2.475828847 trunk 2.475070703 trunk 2.477962812 khash 2.492003189 khash 2.492075036 khash 2.552800777 khash 2.625442984 khash 2.491857117 khash 2.64863233 khash 2.540409817 khash 2.611044242 khash 2.526069365 khash 2.629043327 ----------------------------------------------------------- vm1_neq i = 0 obj1 = Object.new obj2 = Object.new while i<30_000_000 # while loop 1 i += 1 obj1 != obj2 end trunk 0.950580698 trunk 0.973278817 trunk 0.954841753 trunk 0.953689731 trunk 0.950562869 trunk 0.953295582 trunk 0.993703977 trunk 0.963899494 trunk 0.966237017 trunk 0.950930792 khash 0.950204018 khash 0.950297388 khash 0.950620907 khash 0.949043989 khash 0.957987141 khash 0.951762487 khash 0.979138684 khash 1.031885836 khash 1.026139662 khash 0.999131546 ----------------------------------------------------------- vm1_not i = 0 obj = Object.new while i<30_000_000 # while loop 1 i += 1 !obj end trunk 0.76209972 trunk 0.746747057 trunk 0.755207869 trunk 0.746391174 trunk 0.746544915 trunk 0.74742556 trunk 0.746500094 trunk 0.746456077 trunk 0.746320869 trunk 0.745492919 khash 0.746969092 khash 0.747055072 khash 0.746662923 khash 0.776677382 khash 0.780857215 khash 0.770640505 khash 0.757442727 khash 0.77347366 khash 0.812763092 khash 0.792538701 ----------------------------------------------------------- vm1_rescue i = 0 while i<30_000_000 # while loop 1 i += 1 begin rescue end end trunk 0.674351771 trunk 0.737462587 trunk 0.708452896 trunk 0.617818541 trunk 0.748578147 trunk 0.659590781 trunk 0.610155792 trunk 0.643541515 trunk 0.643876384 trunk 0.691503521 khash 0.608365702 khash 0.629520663 khash 0.678443071 khash 0.608671433 khash 0.6079049 khash 0.689370927 khash 0.745057833 khash 0.641111248 khash 0.701300099 khash 0.747643826 ----------------------------------------------------------- vm1_simplereturn def m return 1 end i = 0 while i<30_000_000 # while loop 1 i += 1 m end trunk 1.285106609 trunk 1.444705805 trunk 1.400927033 trunk 1.528697674 trunk 1.370908954 trunk 1.215896308 trunk 1.215774447 trunk 1.215926591 trunk 1.215395219 trunk 1.21647898 khash 1.216168568 khash 1.340137979 khash 1.21683018 khash 1.216016122 khash 1.216084755 khash 1.216190012 khash 1.215355194 khash 1.215814351 khash 1.216047823 khash 1.509987714 ----------------------------------------------------------- vm1_swap a = 1 b = 2 i = 0 while i<30_000_000 # while loop 1 i += 1 a, b = b, a end trunk 0.72963431 trunk 0.729289941 trunk 0.728653884 trunk 0.893276999 trunk 0.729813803 trunk 0.729772251 trunk 0.729449273 trunk 0.729378121 trunk 0.72937277 trunk 0.729434852 khash 0.731073629 khash 0.894452943 khash 0.730736382 khash 0.735737956 khash 0.808653957 khash 0.767124416 khash 0.731762984 khash 0.740166948 khash 0.780069851 khash 0.831061634 ----------------------------------------------------------- vm1_yield def m i = 0 while i<30_000_000 # while loop 1 i += 1 yield end end m{} trunk 1.761305874 trunk 1.761458726 trunk 1.227104501 trunk 1.249586545 trunk 1.226100095 trunk 1.159464594 trunk 1.159304528 trunk 1.158281469 trunk 1.182765234 trunk 1.193587771 khash 1.432093172 khash 1.188360581 khash 1.162043296 khash 1.167964039 khash 1.158821007 khash 1.171047207 khash 1.219919471 khash 1.171346443 khash 1.153041716 khash 1.274471288 ----------------------------------------------------------- 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 0.715780049 trunk 0.724318702 trunk 0.856018022 trunk 0.727317087 trunk 0.725719266 trunk 0.732049589 trunk 0.732047208 trunk 0.722646294 trunk 0.721061278 trunk 0.728003704 khash 0.742402466 khash 0.744946376 khash 0.741701447 khash 0.723363508 khash 0.739689118 khash 0.932491364 khash 0.790058141 khash 0.868948314 khash 0.84563571 khash 0.871442395 ----------------------------------------------------------- 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 7.058071955 trunk 7.093445956 trunk 7.279833096 trunk 7.078441661 trunk 7.245945721 trunk 7.327381889 trunk 6.913526008 trunk 7.266853001 trunk 6.762578486 trunk 6.952103716 khash 6.519600273 khash 6.394676938 khash 6.552518952 khash 7.071549719 khash 7.378185278 khash 7.097745838 khash 7.396764858 khash 7.132354036 khash 7.124932519 khash 7.32564211 ----------------------------------------------------------- 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 3.905002103 trunk 4.044392063 trunk 3.916212964 trunk 4.115563274 trunk 3.880084745 trunk 4.138631142 trunk 3.940803162 trunk 3.926139646 trunk 3.956196298 trunk 4.040121175 khash 3.895682386 khash 3.97129818 khash 4.033659206 khash 3.916017789 khash 3.85871707 khash 3.943324208 khash 3.995234824 khash 4.158595241 khash 4.023755228 khash 3.987391604 ----------------------------------------------------------- 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.195881512 trunk 0.194235296 trunk 0.19582402 trunk 0.200166893 trunk 0.194753905 trunk 0.195699393 trunk 0.1950397 trunk 0.195959823 trunk 0.197732591 trunk 0.195290721 khash 0.194311124 khash 0.194749933 khash 0.199169523 khash 0.194087194 khash 0.194678668 khash 0.194065407 khash 0.194251591 khash 0.194706719 khash 0.193965445 khash 0.194078179 ----------------------------------------------------------- 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 2.732879149 trunk 2.724291484 trunk 4.389127651 trunk 2.729360468 trunk 2.704902466 trunk 2.761801095 trunk 2.788674115 trunk 2.783479073 trunk 3.608102725 trunk 3.971013023 khash 3.310785494 khash 4.286632093 khash 2.743695527 khash 2.750200045 khash 2.730153106 khash 2.715771667 khash 2.757280986 khash 2.761590564 khash 2.750151767 khash 2.733704017 ----------------------------------------------------------- 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 1.206792263 trunk 1.208908501 trunk 1.205096399 trunk 1.35394114 trunk 1.236244654 trunk 1.207908193 trunk 1.905911928 trunk 1.178059112 trunk 1.200213507 trunk 1.307005869 khash 1.212362364 khash 2.35687665 khash 1.193311593 khash 1.188697001 khash 1.190022135 khash 1.617370595 khash 1.192214877 khash 1.190796841 khash 1.191372322 khash 1.191633384 ----------------------------------------------------------- vm2_eval i = 0 while i<6_000_000 # benchmark loop 2 i += 1 eval("1") end trunk 13.189617316 trunk 14.222525599 trunk 15.283028607 trunk 13.388353799 trunk 14.025589713 trunk 13.898685608 trunk 13.35516347 trunk 13.731698356 trunk 15.105784976 trunk 15.455335458 khash 14.461012065 khash 13.872922289 khash 14.813237706 khash 13.607506942 khash 13.96691384 khash 15.151529981 khash 14.511367151 khash 13.831583925 khash 14.565826537 khash 13.47478735 ----------------------------------------------------------- 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 1.344494427 trunk 1.343634735 trunk 1.356123289 trunk 1.346881519 trunk 1.3447599 trunk 1.352478356 trunk 1.398151855 trunk 1.461353429 trunk 1.356912543 trunk 1.367067622 khash 1.355210538 khash 1.35503524 khash 1.519572946 khash 1.416291968 khash 1.435442755 khash 1.457636047 khash 1.445304161 khash 1.531762543 khash 1.482424867 khash 1.353993002 ----------------------------------------------------------- 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 1.945874752 trunk 1.920202769 trunk 1.926268739 trunk 1.948798793 trunk 2.009244392 trunk 1.920294571 trunk 1.957870992 trunk 1.94993399 trunk 1.947333019 trunk 1.920360613 khash 1.993908659 khash 2.006750631 khash 1.929828368 khash 2.074262132 khash 2.177492144 khash 2.172854918 khash 2.195485667 khash 2.154209596 khash 2.235983168 khash 1.954869422 ----------------------------------------------------------- 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 1.665021098 trunk 1.524709261 trunk 1.539980149 trunk 1.525295488 trunk 1.5960152 trunk 1.526591817 trunk 1.54501638 trunk 1.524129051 trunk 1.526546895 trunk 1.525208037 khash 1.533599218 khash 1.567380209 khash 1.631194141 khash 1.707234715 khash 1.616568678 khash 1.528955608 khash 1.534995619 khash 1.533000873 khash 1.702156354 khash 1.647614488 ----------------------------------------------------------- vm2_mutex require 'thread' m = Mutex.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m.synchronize{} end trunk 0.808631928 trunk 0.890022007 trunk 1.147668723 trunk 1.05752463 trunk 0.856655041 trunk 1.228427207 trunk 0.996893492 trunk 0.729140763 trunk 0.72697185 trunk 0.729315264 khash 0.725257896 khash 0.72536585 khash 0.758195659 khash 0.738871373 khash 0.725463827 khash 0.738383871 khash 0.755587921 khash 0.726454536 khash 0.725200677 khash 0.725458431 ----------------------------------------------------------- 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 2.172853825 trunk 2.224659708 trunk 2.220318559 trunk 2.21753776 trunk 2.175417414 trunk 2.170067613 trunk 2.202549364 trunk 2.181547397 trunk 2.232929362 trunk 2.200330718 khash 2.281525098 khash 2.280872273 khash 2.404527944 khash 2.237586325 khash 2.234567188 khash 2.242317271 khash 2.259401831 khash 3.406105077 khash 3.301146641 khash 2.239194565 ----------------------------------------------------------- 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.27277835 trunk 0.272762864 trunk 0.272337592 trunk 0.272967788 trunk 0.273067262 trunk 0.272156922 trunk 0.273142964 trunk 0.273403025 trunk 0.274657761 trunk 0.273145601 khash 0.273296406 khash 0.273241655 khash 0.273211747 khash 0.273353615 khash 0.272989071 khash 0.273005183 khash 0.273461578 khash 0.272746124 khash 0.273966558 khash 0.272999639 ----------------------------------------------------------- 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 0.507317273 trunk 0.506007743 trunk 0.50612656 trunk 0.50913869 trunk 0.506378651 trunk 0.509993118 trunk 0.505017327 trunk 0.505757096 trunk 0.52197253 trunk 0.507074482 khash 0.513669874 khash 0.506385882 khash 0.508901124 khash 0.507902399 khash 0.503953965 khash 0.576495929 khash 0.548307632 khash 0.519813243 khash 0.509969708 khash 0.517675375 ----------------------------------------------------------- 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 5.613369884 trunk 5.550788859 trunk 5.329289337 trunk 5.37355728 trunk 5.336494609 trunk 5.388008644 trunk 5.338847032 trunk 5.673043347 trunk 5.788924504 trunk 5.340436501 khash 5.82232537 khash 5.384043074 khash 5.375003151 khash 5.349027575 khash 5.910607533 khash 6.316611529 khash 5.353892819 khash 5.469923393 khash 5.528589696 khash 5.438228144 ----------------------------------------------------------- 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 8.094231638 trunk 8.024155448 trunk 7.820240959 trunk 7.886812561 trunk 7.965738125 trunk 8.011499913 trunk 8.08226882 trunk 7.806030408 trunk 7.920628906 trunk 7.851387493 khash 8.186583498 khash 8.159430311 khash 7.969321883 khash 8.102495842 khash 7.835807516 khash 7.960722797 khash 7.977497533 khash 7.874188638 khash 7.974401197 khash 7.926955367 ----------------------------------------------------------- vm2_regexp i = 0 str = 'xxxhogexxx' while i<6_000_000 # benchmark loop 2 /hoge/ =~ str i += 1 end trunk 1.161965222 trunk 1.182602741 trunk 1.162755373 trunk 1.160972365 trunk 1.183007071 trunk 1.214392863 trunk 1.215802189 trunk 1.211204313 trunk 1.165949191 trunk 1.212448236 khash 1.207282841 khash 1.203254057 khash 1.177265745 khash 1.169874092 khash 1.173607 khash 1.151789178 khash 1.152501102 khash 1.151857618 khash 1.174070158 khash 1.153079141 ----------------------------------------------------------- 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.379176259 trunk 0.382972117 trunk 0.40378862 trunk 0.37910164 trunk 0.379111978 trunk 0.398525632 trunk 0.379049658 trunk 0.383009245 trunk 0.379234443 trunk 0.378817392 khash 0.390404674 khash 0.38540663 khash 0.380201989 khash 0.383318295 khash 0.41611468 khash 0.381313191 khash 0.379798047 khash 0.380227404 khash 0.383554862 khash 0.380397562 ----------------------------------------------------------- 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 0.507971313 trunk 0.496389111 trunk 0.524848861 trunk 0.51745496 trunk 0.494690789 trunk 0.498633387 trunk 0.500946188 trunk 0.52229273 trunk 0.49543708 trunk 0.502617809 khash 0.498382771 khash 0.586864867 khash 0.49827685 khash 0.531569148 khash 0.498212875 khash 0.499842186 khash 0.498543671 khash 0.498446176 khash 0.498206013 khash 0.500045374 ----------------------------------------------------------- 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.273632411 trunk 0.271555013 trunk 0.275182812 trunk 0.271537642 trunk 0.272209512 trunk 0.274043419 trunk 0.272393794 trunk 0.270891252 trunk 0.271408191 trunk 0.271305773 khash 0.280519714 khash 0.271423533 khash 0.271585338 khash 0.27380976 khash 0.271278746 khash 0.271656834 khash 0.272346451 khash 0.271563485 khash 0.302126894 khash 0.28887247 ----------------------------------------------------------- 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 0.533236845 trunk 0.511685786 trunk 0.573486404 trunk 0.513292601 trunk 0.539275586 trunk 0.546745287 trunk 0.512360199 trunk 0.523237748 trunk 0.555191689 trunk 0.558281994 khash 0.543724325 khash 0.542836315 khash 0.51516352 khash 0.533485662 khash 0.53158332 khash 0.538321393 khash 0.545296131 khash 0.557320686 khash 0.516273021 khash 0.515000576 ----------------------------------------------------------- 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.148014017 trunk 0.144184411 trunk 0.144394825 trunk 0.144388851 trunk 0.143969495 trunk 0.144333673 trunk 0.14395445 trunk 0.14361258 trunk 0.144237755 trunk 0.14636067 khash 0.14498183 khash 0.145361381 khash 0.144963305 khash 0.14522337 khash 0.144812279 khash 0.149919185 khash 0.14489302 khash 0.144960478 khash 0.144594593 khash 0.14498198 ----------------------------------------------------------- vm3_clearmethodcache i = 0 while i<200_000 i += 1 Class.new{ def m; end } end trunk 0.391644657 trunk 0.392770777 trunk 0.388915121 trunk 0.391178102 trunk 0.388136604 trunk 0.388293625 trunk 0.391996831 trunk 0.388687456 trunk 0.3890298 trunk 0.38706578 khash 0.414425023 khash 0.391579319 khash 0.409701071 khash 0.390664384 khash 0.392960498 khash 0.384042186 khash 0.411326743 khash 0.387260299 khash 0.384349685 khash 0.385812124 ----------------------------------------------------------- vm3_gc #! /usr/bin/ruby 5000.times do 100.times do {"xxxx"=>"yyyy"} end GC.start end trunk 1.769321156 trunk 1.779826446 trunk 1.775015085 trunk 1.777837159 trunk 1.774071912 trunk 1.779756188 trunk 1.784497745 trunk 1.773407652 trunk 1.779836179 trunk 1.819306645 khash 1.836530216 khash 1.77694535 khash 1.763972258 khash 1.811434344 khash 1.761057516 khash 1.775490397 khash 1.803287131 khash 1.755144681 khash 1.793912119 khash 1.775633027 ----------------------------------------------------------- vm_thread_alive_check1 5_000.times{ t = Thread.new{} while t.alive? Thread.pass end } trunk 0.105810641 trunk 0.103199588 trunk 0.099450834 trunk 0.099177191 trunk 0.101942219 trunk 0.10319973 trunk 0.103725253 trunk 0.105172026 trunk 0.108842007 trunk 0.105655954 khash 0.106287675 khash 0.102197884 khash 0.103350428 khash 0.102061412 khash 0.102178602 khash 0.102870382 khash 0.103685614 khash 0.102671045 khash 0.101999242 khash 0.101976966 ----------------------------------------------------------- vm_thread_close 1000.times { Thread.new { sleep } } i = 0 while i<100_000 # benchmark loop 3 i += 1 IO.pipe.each(&:close) end trunk 3.093359842 trunk 3.122353613 trunk 3.079157735 trunk 3.011448924 trunk 3.163090655 trunk 3.112596036 trunk 3.172880293 trunk 3.212529457 trunk 3.165536778 trunk 3.237523688 khash 3.184895409 khash 2.962322488 khash 3.289033335 khash 3.054456051 khash 3.152899397 khash 3.085772742 khash 3.101733894 khash 3.244143479 khash 2.539010497 khash 3.118460159 ----------------------------------------------------------- vm_thread_create_join i = 0 while i<100_000 # benchmark loop 3 i += 1 Thread.new{ }.join end trunk 1.172530101 trunk 1.176799256 trunk 1.173793459 trunk 1.167924498 trunk 1.218923875 trunk 1.182879618 trunk 1.178262501 trunk 1.165927145 trunk 1.165766477 trunk 1.174827249 khash 1.243380967 khash 1.190462617 khash 1.209649313 khash 1.17512461 khash 1.187413286 khash 1.167228008 khash 1.185326443 khash 1.191454538 khash 1.211446271 khash 1.198219545 ----------------------------------------------------------- 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