Sun Apr 28 16:10:32 +0900 2013 target 0: trunk (ruby 2.1.0dev (2013-04-28 trunk 40512) [x86_64-linux]) at "/home/ko1/tmp/trunk/bin/ruby" target 1: rgengc (ruby 2.1.0dev (2013-04-28 trunk 40512) [x86_64-linux]) at "/home/ko1/tmp/gitruby/bin/ruby" ----------------------------------------------------------- app_answer def ack(m, n) if m == 0 then n + 1 elsif n == 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end def the_answer_to_life_the_universe_and_everything (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i end answer = the_answer_to_life_the_universe_and_everything trunk 0.135365962982178 trunk 0.127779006958008 trunk 0.127289056777954 trunk 0.134907007217407 trunk 0.127953052520752 trunk 0.132900953292847 trunk 0.127893924713135 trunk 0.134672880172729 trunk 0.144860982894897 trunk 0.127792119979858 rgengc 0.129174947738647 rgengc 0.142368078231812 rgengc 0.128683090209961 rgengc 0.12909197807312 rgengc 0.138580799102783 rgengc 0.128704071044922 rgengc 0.133697032928467 rgengc 0.134521961212158 rgengc 0.13459300994873 rgengc 0.128439903259277 ----------------------------------------------------------- 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 def x=(v); @x = v; end def y=(v); @y = v; end def z=(v); @z = v; end def x; @x; end def y; @y; end def z; @z; end 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 def center; @center; end def radius; @radius; end 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 def org; @org; end def org=(v); @org = v; end def dir; @dir; end def dir=(v); @dir = v; end 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 def t; @t; end def t=(v); @t = v; end def hit; @hit; end def hit=(v); @hit = v; end def pl; @pl; end def pl=(v); @pl = v; end def n; @n; end def n=(v); @n = v; end 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 # File.open("ao.ppm", "w") do |fp| def $stdout.write *args # ignore output for benchmark end 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 trunk 157.279587984085 trunk 156.637433052063 trunk 159.278604030609 trunk 159.127108097076 trunk 158.91048002243 trunk 158.777278184891 trunk 160.784476041794 trunk 155.907822132111 trunk 156.597125053406 trunk 157.10164308548 rgengc 165.574127197266 rgengc 167.765599966049 rgengc 165.520746946335 rgengc 167.666110992432 rgengc 165.113090991974 rgengc 164.706486940384 rgengc 172.62554693222 rgengc 166.214869022369 rgengc 163.861956834793 rgengc 165.062297105789 ----------------------------------------------------------- app_erb # # Create many HTML strings with ERB. # require 'erb' data = DATA.read max = 15_000 title = "hello world!" content = "hello world!\n" * 10 max.times{ ERB.new(data).result(binding) } __END__ <%= title %>

<%= title %>

<%= content %>

trunk 2.69433498382568 trunk 2.68459320068359 trunk 2.689129114151 trunk 2.68919086456299 trunk 2.70899105072021 trunk 2.68947696685791 trunk 2.68746209144592 trunk 2.69248104095459 trunk 2.70198678970337 trunk 2.69166994094849 rgengc 2.69082808494568 rgengc 2.71505498886108 rgengc 2.72545695304871 rgengc 2.71992492675781 rgengc 2.71765303611755 rgengc 2.73884797096252 rgengc 2.70833683013916 rgengc 2.72491598129272 rgengc 2.72130703926086 rgengc 2.71506094932556 ----------------------------------------------------------- app_factorial def fact(n) if(n > 1) n * fact(n-1) else 1 end end 100.times { fact(5000) } trunk 2.75848197937012 trunk 2.74770903587341 trunk 2.75065493583679 trunk 2.76164507865906 trunk 2.74511289596558 trunk 2.76851296424866 trunk 2.76209187507629 trunk 2.76473712921143 trunk 2.75826597213745 trunk 2.75852489471436 rgengc 2.76618194580078 rgengc 2.76832389831543 rgengc 2.76442313194275 rgengc 2.77586889266968 rgengc 2.7837381362915 rgengc 2.7637779712677 rgengc 2.76390910148621 rgengc 2.76500701904297 rgengc 2.76244688034058 rgengc 2.7679591178894 ----------------------------------------------------------- app_fib def fib n if n < 3 1 else fib(n-1) + fib(n-2) end end fib(34) trunk 1.25332307815552 trunk 1.12053608894348 trunk 1.41413712501526 trunk 1.09795188903809 trunk 1.10024690628052 trunk 1.24303507804871 trunk 1.09780716896057 trunk 1.37455010414124 trunk 1.26781988143921 trunk 1.1813051700592 rgengc 1.13109183311462 rgengc 1.06730318069458 rgengc 1.11004304885864 rgengc 1.11723303794861 rgengc 1.07333898544312 rgengc 1.12381792068481 rgengc 1.13865113258362 rgengc 1.1985080242157 rgengc 1.06726384162903 rgengc 1.07312393188477 ----------------------------------------------------------- app_mandelbrot require 'complex' def mandelbrot? z i = 0 while i<100 i += 1 z = z * z return false if z.abs > 2 end true end ary = [] (0..1000).each{|dx| (0..1000).each{|dy| x = dx / 50.0 y = dy / 50.0 c = Complex(x, y) ary << c if mandelbrot?(c) } } trunk 2.69271492958069 trunk 2.6780788898468 trunk 2.59261989593506 trunk 2.6506679058075 trunk 2.62361001968384 trunk 2.53092098236084 trunk 2.69711685180664 trunk 2.61248898506165 trunk 2.63207101821899 trunk 2.602942943573 rgengc 2.6623170375824 rgengc 2.71026110649109 rgengc 2.65510702133179 rgengc 2.67376494407654 rgengc 2.68447399139404 rgengc 2.668044090271 rgengc 2.67371106147766 rgengc 2.69270610809326 rgengc 2.63504314422607 rgengc 2.70443415641785 ----------------------------------------------------------- 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 37.9749398231506 trunk 37.2498180866241 trunk 38.1691901683807 trunk 37.8972980976105 trunk 38.3245210647583 trunk 37.9370808601379 trunk 38.2795469760895 trunk 37.9341261386871 trunk 38.3363521099091 trunk 37.4297859668732 rgengc 41.7761878967285 rgengc 40.0619781017303 rgengc 39.3941650390625 rgengc 39.6054680347443 rgengc 39.6223609447479 rgengc 39.1908731460571 rgengc 40.1942009925842 rgengc 39.4775021076202 rgengc 39.7900109291077 rgengc 39.896341085434 ----------------------------------------------------------- app_raise i = 0 while i<300000 i += 1 begin raise rescue end end trunk 0.704020023345947 trunk 0.715256929397583 trunk 0.705376863479614 trunk 0.723409175872803 trunk 0.724014043807983 trunk 0.704705953598022 trunk 0.708616971969604 trunk 0.712412118911743 trunk 0.720111131668091 trunk 0.713053941726685 rgengc 0.707025051116943 rgengc 0.705502033233643 rgengc 0.701291084289551 rgengc 0.69818902015686 rgengc 0.704543113708496 rgengc 0.700436115264893 rgengc 0.686985969543457 rgengc 0.710025787353516 rgengc 0.700164079666138 rgengc 0.690780162811279 ----------------------------------------------------------- app_strconcat i = 0 while i<2_000_000 "#{1+1} #{1+1} #{1+1}" i += 1 end trunk 2.46226215362549 trunk 2.45072507858276 trunk 2.39072108268738 trunk 2.47019195556641 trunk 2.46631908416748 trunk 2.42093205451965 trunk 2.4565110206604 trunk 2.43358397483826 trunk 2.42681884765625 trunk 2.41242003440857 rgengc 2.48242712020874 rgengc 2.46189904212952 rgengc 2.45225501060486 rgengc 2.47973299026489 rgengc 2.51965308189392 rgengc 2.46556615829468 rgengc 2.46493697166443 rgengc 2.50097298622131 rgengc 2.47722697257996 rgengc 2.46838188171387 ----------------------------------------------------------- app_tak def tak x, y, z unless y < x z else tak( tak(x-1, y, z), tak(y-1, z, x), tak(z-1, x, y)) end end tak(18, 9, 0) trunk 1.49210810661316 trunk 1.54962205886841 trunk 1.55875682830811 trunk 1.62422704696655 trunk 1.47428488731384 trunk 1.55819511413574 trunk 1.57940101623535 trunk 1.56594204902649 trunk 1.52752995491028 trunk 1.43291401863098 rgengc 1.60133600234985 rgengc 1.56357789039612 rgengc 1.59191179275513 rgengc 1.51550602912903 rgengc 1.56863689422607 rgengc 1.53386807441711 rgengc 1.53059792518616 rgengc 1.54890704154968 rgengc 1.53869295120239 rgengc 1.53531289100647 ----------------------------------------------------------- app_tarai def tarai( x, y, z ) if x <= y then y else tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y)) end end tarai(12, 6, 0) trunk 1.26126289367676 trunk 1.25521302223206 trunk 1.24869084358215 trunk 1.25639390945435 trunk 1.32526302337646 trunk 1.29220199584961 trunk 1.25951099395752 trunk 1.24506592750549 trunk 1.27952718734741 trunk 1.25498914718628 rgengc 1.27170896530151 rgengc 1.30037879943848 rgengc 1.30236291885376 rgengc 1.25673794746399 rgengc 1.26221394538879 rgengc 1.23008894920349 rgengc 1.26435017585754 rgengc 1.48550391197205 rgengc 1.24896192550659 rgengc 1.28488802909851 ----------------------------------------------------------- app_uri require 'uri' 100_000.times{ uri = URI.parse('http://www.ruby-lang.org') uri.scheme uri.host uri.port } trunk 2.1625120639801 trunk 2.15934181213379 trunk 2.15623712539673 trunk 2.17099690437317 trunk 2.17010307312012 trunk 2.16804504394531 trunk 2.14200806617737 trunk 2.16679382324219 trunk 2.16451382637024 trunk 2.15759992599487 rgengc 2.24038290977478 rgengc 2.2275288105011 rgengc 2.24567890167236 rgengc 2.24570989608765 rgengc 2.24020600318909 rgengc 2.2452609539032 rgengc 2.24559497833252 rgengc 2.25089502334595 rgengc 2.23930907249451 rgengc 2.23969602584839 ----------------------------------------------------------- hash_shift h = {} 10000.times do |i| h[i] = nil end 50000.times do k, v = h.shift h[k] = v end trunk 0.083158016204834 trunk 0.0825519561767578 trunk 0.083549976348877 trunk 0.0835840702056885 trunk 0.0838680267333984 trunk 0.0829439163208008 trunk 0.0831279754638672 trunk 0.0825610160827637 trunk 0.0827970504760742 trunk 0.0829241275787354 rgengc 0.0850820541381836 rgengc 0.0840330123901367 rgengc 0.0847189426422119 rgengc 0.0844049453735352 rgengc 0.0844099521636963 rgengc 0.084507942199707 rgengc 0.0846588611602783 rgengc 0.0849840641021729 rgengc 0.0833580493927002 rgengc 0.0842139720916748 ----------------------------------------------------------- io_file_create # # Create files # max = 200_000 file = './tmpfile_of_bm_io_file_create' max.times{ f = open(file, 'w') f.close#(true) } File.unlink(file) trunk 2.72065615653992 trunk 2.70182800292969 trunk 2.63341403007507 trunk 2.72156000137329 trunk 2.65619707107544 trunk 2.70008015632629 trunk 2.66922998428345 trunk 2.67633700370789 trunk 2.6394829750061 trunk 2.67151212692261 rgengc 2.62578082084656 rgengc 2.62885093688965 rgengc 2.61474299430847 rgengc 2.61840605735779 rgengc 2.61053204536438 rgengc 2.55880904197693 rgengc 2.59668612480164 rgengc 2.65679812431335 rgengc 2.58704209327698 rgengc 2.59838700294495 ----------------------------------------------------------- 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 8.29551196098328 trunk 8.21008992195129 trunk 8.19729089736938 trunk 8.3041250705719 trunk 8.17046594619751 trunk 8.20086908340454 trunk 7.63104581832886 trunk 8.29939293861389 trunk 8.2077488899231 trunk 8.2604649066925 rgengc 8.38964605331421 rgengc 8.27964186668396 rgengc 8.27829599380493 rgengc 8.32760000228882 rgengc 8.35395097732544 rgengc 8.29023408889771 rgengc 8.28373098373413 rgengc 8.19959402084351 rgengc 8.31598377227783 rgengc 8.30303001403809 ----------------------------------------------------------- io_file_write # # Seek and Write file. # require 'tempfile' max = 200_000 str = "Hello world! " * 1000 f = Tempfile.new('yarv-benchmark') max.times{ f.seek 0 f.write str } trunk 2.28416514396667 trunk 2.27663803100586 trunk 2.34157395362854 trunk 2.29510593414307 trunk 2.38278293609619 trunk 2.31108784675598 trunk 2.35877203941345 trunk 2.31023502349854 trunk 2.33867287635803 trunk 2.30513000488281 rgengc 2.31663203239441 rgengc 2.35717701911926 rgengc 2.31529188156128 rgengc 2.37297892570496 rgengc 2.31368589401245 rgengc 2.30075812339783 rgengc 2.36380386352539 rgengc 2.27285289764404 rgengc 2.36703085899353 rgengc 2.29596400260925 ----------------------------------------------------------- io_select # IO.select performance w = [ IO.pipe[1] ]; nr = 1000000 nr.times { IO.select nil, w } trunk 3.22312784194946 trunk 3.25546288490295 trunk 3.18548393249512 trunk 3.25086688995361 trunk 3.23107194900513 trunk 3.11094117164612 trunk 3.18007707595825 trunk 3.25176692008972 trunk 3.25952696800232 trunk 3.25467491149902 rgengc 3.06700611114502 rgengc 3.13624286651611 rgengc 3.08072900772095 rgengc 3.01989507675171 rgengc 3.06834197044373 rgengc 3.15792608261108 rgengc 3.02316212654114 rgengc 3.29092001914978 rgengc 3.03139805793762 rgengc 3.27249979972839 ----------------------------------------------------------- io_select2 # IO.select performance. worst case of single fd. ios = [] nr = 1000000 if defined?(Process::RLIMIT_NOFILE) max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] else max = 64 end puts "max fd: #{max} (results not apparent with <= 1024 max fd)" ((max / 2) - 10).times do ios.concat IO.pipe end last = [ ios[-1] ] puts "last IO: #{last[0].inspect}" nr.times do IO.select nil, last end trunk 4.06562185287476 trunk 4.10718202590942 trunk 4.0440309047699 trunk 4.07019805908203 trunk 4.0355658531189 trunk 3.94979405403137 trunk 3.94400095939636 trunk 4.02141213417053 trunk 3.98904895782471 trunk 4.02587795257568 rgengc 3.82136607170105 rgengc 3.83059096336365 rgengc 3.87420701980591 rgengc 3.99592900276184 rgengc 3.90101504325867 rgengc 3.92434811592102 rgengc 4.02656316757202 rgengc 3.82772397994995 rgengc 3.84120988845825 rgengc 3.86650609970093 ----------------------------------------------------------- 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.081744909286499 trunk 0.0818250179290771 trunk 0.0825889110565186 trunk 0.0825471878051758 trunk 0.0824620723724365 trunk 0.0827760696411133 trunk 0.0819981098175049 trunk 0.0822339057922363 trunk 0.082150936126709 trunk 0.0820422172546387 rgengc 0.0814700126647949 rgengc 0.0838189125061035 rgengc 0.0841920375823975 rgengc 0.0836632251739502 rgengc 0.0821108818054199 rgengc 0.0811841487884521 rgengc 0.0838649272918701 rgengc 0.081071138381958 rgengc 0.0842680931091309 rgengc 0.0822250843048096 ----------------------------------------------------------- loop_for for i in 1..30_000_000 # end trunk 2.709557056427 trunk 2.71784687042236 trunk 2.70662188529968 trunk 2.7732470035553 trunk 2.70774793624878 trunk 2.90968680381775 trunk 2.70387482643127 trunk 2.90775489807129 trunk 2.70547914505005 trunk 2.7124810218811 rgengc 2.73180603981018 rgengc 2.8453209400177 rgengc 2.7088520526886 rgengc 2.71397590637207 rgengc 3.14006495475769 rgengc 2.7476019859314 rgengc 2.72425198554993 rgengc 2.78373408317566 rgengc 2.72495102882385 rgengc 2.72564601898193 ----------------------------------------------------------- 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.978506088256836 trunk 0.98500394821167 trunk 0.971513986587524 trunk 0.973932027816772 trunk 0.974906921386719 trunk 0.973211050033569 trunk 0.976495027542114 trunk 0.975392818450928 trunk 0.971909046173096 trunk 0.972767114639282 rgengc 1.00487685203552 rgengc 0.997107982635498 rgengc 0.992351055145264 rgengc 0.991833925247192 rgengc 0.993476867675781 rgengc 1.02008509635925 rgengc 1.00472688674927 rgengc 0.994802951812744 rgengc 1.00923800468445 rgengc 1.00514578819275 ----------------------------------------------------------- loop_times 30_000_000.times{|e|} trunk 2.5911169052124 trunk 2.61421918869019 trunk 2.60349798202515 trunk 2.89805316925049 trunk 2.60905289649963 trunk 2.63157606124878 trunk 2.60178279876709 trunk 2.61498999595642 trunk 2.61405611038208 trunk 2.61933088302612 rgengc 2.65669703483582 rgengc 2.64346098899841 rgengc 2.66437911987305 rgengc 2.6811740398407 rgengc 2.65264415740967 rgengc 2.67656302452087 rgengc 2.8703351020813 rgengc 2.78816199302673 rgengc 2.90213012695312 rgengc 2.63119792938232 ----------------------------------------------------------- loop_whileloop i = 0 while i<30_000_000 # benchmark loop 1 i += 1 end trunk 0.998850107192993 trunk 0.994848012924194 trunk 0.993263959884644 trunk 0.998544931411743 trunk 0.995316982269287 trunk 1.04746699333191 trunk 1.04662013053894 trunk 0.994854927062988 trunk 1.04508900642395 trunk 0.997917890548706 rgengc 1.0320680141449 rgengc 1.02598905563354 rgengc 1.03640103340149 rgengc 1.04791712760925 rgengc 1.03285098075867 rgengc 1.0360119342804 rgengc 1.04832696914673 rgengc 1.04987001419067 rgengc 1.03127813339233 rgengc 1.03968405723572 ----------------------------------------------------------- loop_whileloop2 i = 0 while i< 6_000_000 # benchmark loop 2 i += 1 end trunk 0.23186993598938 trunk 0.241132974624634 trunk 0.231405019760132 trunk 0.232249975204468 trunk 0.231718063354492 trunk 0.231257915496826 trunk 0.231281042098999 trunk 0.231992959976196 trunk 0.332093000411987 trunk 0.231055021286011 rgengc 0.241803169250488 rgengc 0.241267919540405 rgengc 0.238978862762451 rgengc 0.242524147033691 rgengc 0.23928689956665 rgengc 0.238874912261963 rgengc 0.246927976608276 rgengc 0.242541074752808 rgengc 0.239728212356567 rgengc 0.243839025497437 ----------------------------------------------------------- so_ackermann #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ def ack(m, n) if m == 0 then n + 1 elsif n == 0 then ack(m - 1, 1) else ack(m - 1, ack(m, n - 1)) end end NUM = 9 ack(3, NUM) trunk 1.45328116416931 trunk 1.52703499794006 trunk 1.6527988910675 trunk 1.56302189826965 trunk 1.4620099067688 trunk 1.6580970287323 trunk 1.56259512901306 trunk 1.65233302116394 trunk 1.45684480667114 trunk 1.572350025177 rgengc 1.4649510383606 rgengc 1.5499279499054 rgengc 1.47091698646545 rgengc 1.46784687042236 rgengc 1.55430507659912 rgengc 1.46358799934387 rgengc 1.46307396888733 rgengc 1.58047008514404 rgengc 1.69317293167114 rgengc 1.46305990219116 ----------------------------------------------------------- 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 2.17333984375 trunk 2.28449702262878 trunk 2.22501611709595 trunk 2.17094397544861 trunk 2.19826507568359 trunk 2.17194795608521 trunk 2.16403007507324 trunk 2.18615293502808 trunk 2.17374086380005 trunk 2.63465690612793 rgengc 2.20334315299988 rgengc 2.19430017471313 rgengc 2.21849894523621 rgengc 2.21885108947754 rgengc 2.21381616592407 rgengc 2.23430013656616 rgengc 2.23031401634216 rgengc 2.40565085411072 rgengc 2.3514769077301 rgengc 2.23338389396667 ----------------------------------------------------------- so_binary_trees # The Computer Language Shootout Benchmarks # http://shootout.alioth.debian.org # # contributed by Jesse Millikan # disable output def STDOUT.write_ *args 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 = 12 # 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)}" trunk 0.738508939743042 trunk 0.745535135269165 trunk 0.76528000831604 trunk 0.754057168960571 trunk 0.761286020278931 trunk 0.784466981887817 trunk 0.771762847900391 trunk 0.801009893417358 trunk 0.758517026901245 trunk 0.76420783996582 rgengc 0.760326147079468 rgengc 0.775032997131348 rgengc 0.764158010482788 rgengc 0.774486064910889 rgengc 0.740767002105713 rgengc 0.76642107963562 rgengc 0.750844955444336 rgengc 0.777812957763672 rgengc 0.723896980285645 rgengc 0.773517847061157 ----------------------------------------------------------- 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 7.98657202720642 trunk 7.90843796730042 trunk 8.21287703514099 trunk 7.9242160320282 trunk 7.95941400527954 trunk 8.79220986366272 trunk 7.94417595863342 trunk 7.97122120857239 trunk 7.97662711143494 trunk 7.92774105072021 rgengc 8.041179895401 rgengc 8.04370617866516 rgengc 8.03849291801453 rgengc 8.00466895103455 rgengc 8.02473211288452 rgengc 7.96300792694092 rgengc 8.01010203361511 rgengc 8.05460500717163 rgengc 8.02139592170715 rgengc 8.16782903671265 ----------------------------------------------------------- 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.576493978500366 trunk 0.446879863739014 trunk 0.443120002746582 trunk 0.446791887283325 trunk 0.44462513923645 trunk 0.448263883590698 trunk 0.448002815246582 trunk 0.444784879684448 trunk 0.444067001342773 trunk 0.444769144058228 rgengc 0.449738025665283 rgengc 0.450858116149902 rgengc 0.449588060379028 rgengc 0.447092056274414 rgengc 0.44645094871521 rgengc 0.447324991226196 rgengc 0.448033809661865 rgengc 0.451014995574951 rgengc 0.444869041442871 rgengc 0.447550058364868 ----------------------------------------------------------- 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.764631986618042 trunk 0.800068855285645 trunk 0.785394906997681 trunk 0.769979953765869 trunk 0.773189067840576 trunk 0.773983955383301 trunk 0.777693033218384 trunk 0.798179864883423 trunk 0.767920017242432 trunk 0.774296998977661 rgengc 0.760778903961182 rgengc 0.733587980270386 rgengc 0.769947052001953 rgengc 0.778445959091187 rgengc 0.750361919403076 rgengc 0.750637054443359 rgengc 0.743320226669312 rgengc 0.753405094146729 rgengc 0.748960971832275 rgengc 0.767152070999146 ----------------------------------------------------------- so_fannkuch # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura # Modified by Ryan Williams def fannkuch(n) maxFlips, m, r, check = 0, n-1, n, 0 count = (1..n).to_a perm = (1..n).to_a while true if check < 30 puts "#{perm}" check += 1 end while r != 1 count[r-1] = r r -= 1 end if perm[0] != 1 and perm[m] != n perml = perm.clone #.dup flips = 0 while (k = perml.first ) != 1 perml = perml.slice!(0, k).reverse + perml flips += 1 end maxFlips = flips if flips > maxFlips end while true if r==n then return maxFlips end perm.insert r,perm.shift break if (count[r] -= 1) > 0 r += 1 end end end def puts *args end N = 9 # (ARGV[0] || 1).to_i puts "Pfannkuchen(#{N}) = #{fannkuch(N)}" trunk 3.18411993980408 trunk 3.18424606323242 trunk 3.24030804634094 trunk 3.20088315010071 trunk 3.14582896232605 trunk 3.14790678024292 trunk 3.23421502113342 trunk 3.16184496879578 trunk 3.18548107147217 trunk 3.16534495353699 rgengc 3.47667503356934 rgengc 3.46369504928589 rgengc 3.46611404418945 rgengc 3.42538595199585 rgengc 3.4557580947876 rgengc 3.44197010993958 rgengc 3.43682312965393 rgengc 3.44137692451477 rgengc 3.40110993385315 rgengc 3.49187111854553 ----------------------------------------------------------- so_fasta # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura $last = 42.0 def gen_random (max,im=139968,ia=3877,ic=29573) (max * ($last = ($last * ia + ic) % im)) / im end alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" iub = [ ["a", 0.27], ["c", 0.12], ["g", 0.12], ["t", 0.27], ["B", 0.02], ["D", 0.02], ["H", 0.02], ["K", 0.02], ["M", 0.02], ["N", 0.02], ["R", 0.02], ["S", 0.02], ["V", 0.02], ["W", 0.02], ["Y", 0.02], ] homosapiens = [ ["a", 0.3029549426680], ["c", 0.1979883004921], ["g", 0.1975473066391], ["t", 0.3015094502008], ] def make_repeat_fasta(id, desc, src, n) puts ">#{id} #{desc}" v = nil width = 60 l = src.length s = src * ((n / l) + 1) s.slice!(n, l) puts(s.scan(/.{1,#{width}}/).join("\n")) end def make_random_fasta(id, desc, table, n) puts ">#{id} #{desc}" rand, v = nil,nil width = 60 chunk = 1 * width prob = 0.0 table.each{|v| v[1]= (prob += v[1])} for i in 1..(n/width) puts((1..width).collect{ rand = gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end if n%width != 0 puts((1..(n%width)).collect{ rand = gen_random(1.0) table.find{|v| v[1]>rand}[0] }.join) end end n = (ARGV[0] or 250_000).to_i make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2) make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3) make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5) trunk 4.21356391906738 trunk 4.28835701942444 trunk 4.23070192337036 trunk 4.21668791770935 trunk 4.33681082725525 trunk 4.1505868434906 trunk 4.23441195487976 trunk 4.22833108901978 trunk 4.19838190078735 trunk 4.09436798095703 rgengc 4.57137417793274 rgengc 4.54330110549927 rgengc 4.530198097229 rgengc 4.5903000831604 rgengc 4.51314902305603 rgengc 4.64057898521423 rgengc 4.51523089408875 rgengc 4.60662913322449 rgengc 4.55951404571533 rgengc 4.56251215934753 ----------------------------------------------------------- so_k_nucleotide # The Computer Language Shootout # http://shootout.alioth.debian.org # # contributed by jose fco. gonzalez # modified by Sokolov Yura seq = String.new def frecuency( seq,length ) n, table = seq.length - length + 1, Hash.new(0) f, i = nil, nil (0 ... length).each do |f| (f ... n).step(length) do |i| table[seq[i,length]] += 1 end end [n,table] end def sort_by_freq( seq,length ) n,table = frecuency( seq,length ) a, b, v = nil, nil, nil table.sort{|a,b| b[1] <=> a[1]}.each do |v| puts "%s %.3f" % [v[0].upcase,((v[1]*100).to_f/n)] end puts end def find_seq( seq,s ) n,table = frecuency( seq,s.length ) puts "#{table[s].to_s}\t#{s.upcase}" end input = open(File.join(File.dirname($0), 'fasta.output.100000'), 'rb') line = input.gets while line !~ /^>THREE/ line = input.gets while (line !~ /^>/) & line do seq << line.chomp line = input.gets end [1,2].each {|i| sort_by_freq( seq,i ) } %w(ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt).each{|s| find_seq( seq,s) } trunk 2.98903107643127 trunk 2.94342684745789 trunk 2.96464085578918 trunk 2.93974113464355 trunk 2.94347596168518 trunk 3.00617289543152 trunk 3.0060510635376 trunk 2.99322199821472 trunk 2.93008613586426 trunk 3.00736713409424 rgengc 3.13143706321716 rgengc 3.07921099662781 rgengc 3.10640215873718 rgengc 3.09474515914917 rgengc 3.10488986968994 rgengc 3.11617088317871 rgengc 3.19358015060425 rgengc 3.12054395675659 rgengc 3.12103605270386 rgengc 3.11468291282654 ----------------------------------------------------------- so_lists #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby NUM = 300 SIZE = 10000 def test_lists() # create a list of integers (Li1) from 1 to SIZE li1 = (1..SIZE).to_a # copy the list to li2 (not by individual items) li2 = li1.dup # remove each individual item from left side of li2 and # append to right side of li3 (preserving order) li3 = Array.new while (not li2.empty?) li3.push(li2.shift) end # li2 must now be empty # remove each individual item from right side of li3 and # append to right side of li2 (reversing list) while (not li3.empty?) li2.push(li3.pop) end # li3 must now be empty # reverse li1 in place li1.reverse! # check that first item is now SIZE if li1[0] != SIZE then p "not SIZE" 0 else # compare li1 and li2 for equality if li1 != li2 then return(0) else # return the length of the list li1.length end end end i = 0 while i LIMIT_SQUARED escape = true break end end byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1) bit_num += 1 # Code is very similar for these cases, but using separate blocks # ensures we skip the shifting when it's unnecessary, which is most cases. if (bit_num == 8) print byte_acc.chr byte_acc = 0 bit_num = 0 elsif (x == count_size) byte_acc <<= (8 - bit_num) print byte_acc.chr byte_acc = 0 bit_num = 0 end end end trunk 5.85353708267212 trunk 5.65815782546997 trunk 5.93427991867065 trunk 5.70634007453918 trunk 5.64817190170288 trunk 5.47335290908813 trunk 5.98883199691772 trunk 5.78196501731873 trunk 5.65492010116577 trunk 5.74845790863037 rgengc 5.78821611404419 rgengc 6.03932404518127 rgengc 6.10537910461426 rgengc 5.78573298454285 rgengc 5.59161400794983 rgengc 5.91098523139954 rgengc 5.69349384307861 rgengc 6.14773797988892 rgengc 5.87358784675598 rgengc 5.89381194114685 ----------------------------------------------------------- so_matrix #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ n = 60 #Integer(ARGV.shift || 1) size = 40 def mkmatrix(rows, cols) count = 1 mx = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| row[j] = count count += 1 end mx[bi] = row end mx end def mmult(rows, cols, m1, m2) m3 = Array.new(rows) (0 .. (rows - 1)).each do |bi| row = Array.new(cols, 0) (0 .. (cols - 1)).each do |j| val = 0 (0 .. (cols - 1)).each do |k| val += m1.at(bi).at(k) * m2.at(k).at(j) end row[j] = val end m3[bi] = row end m3 end m1 = mkmatrix(size, size) m2 = mkmatrix(size, size) mm = Array.new n.times do mm = mmult(size, size, m1, m2) end # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}" trunk 1.53427004814148 trunk 1.49792003631592 trunk 1.50741791725159 trunk 1.52493596076965 trunk 1.5143461227417 trunk 1.51035308837891 trunk 1.53612899780273 trunk 1.51577615737915 trunk 1.49774312973022 trunk 1.496089220047 rgengc 1.61254692077637 rgengc 1.51375508308411 rgengc 1.61749410629272 rgengc 1.50505304336548 rgengc 1.5301251411438 rgengc 1.49743103981018 rgengc 1.55390000343323 rgengc 1.49851012229919 rgengc 1.58765912055969 rgengc 1.62027597427368 ----------------------------------------------------------- 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 boundries 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 accross the rows (location / 6).to_i.upto(9) do | row_on | # obtain a set of regions representing the bits of the curent 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 muliple 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 # follwing 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 noticable 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 7.18458414077759 trunk 7.13650512695312 trunk 7.1552882194519 trunk 7.19220495223999 trunk 7.07955980300903 trunk 7.24764108657837 trunk 7.1824848651886 trunk 7.15608310699463 trunk 7.06595778465271 trunk 7.21827793121338 rgengc 7.78580784797668 rgengc 7.86049604415894 rgengc 7.59175801277161 rgengc 7.69599103927612 rgengc 7.66655898094177 rgengc 7.88674211502075 rgengc 7.82884621620178 rgengc 7.63166093826294 rgengc 7.69078493118286 rgengc 7.69389295578003 ----------------------------------------------------------- so_nbody # The Computer Language Shootout # http://shootout.alioth.debian.org # # Optimized for Ruby by Jesse Millikan # From version ported by Michael Neumann from the C gcc version, # which was written by Christoph Bauer. SOLAR_MASS = 4 * Math::PI**2 DAYS_PER_YEAR = 365.24 def _puts *args end class Planet attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass def initialize(x, y, z, vx, vy, vz, mass) @x, @y, @z = x, y, z @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR @mass = mass * SOLAR_MASS end def move_from_i(bodies, nbodies, dt, i) while i < nbodies b2 = bodies[i] dx = @x - b2.x dy = @y - b2.y dz = @z - b2.z distance = Math.sqrt(dx * dx + dy * dy + dz * dz) mag = dt / (distance * distance * distance) b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag @vx -= dx * b2_mass_mag @vy -= dy * b2_mass_mag @vz -= dz * b2_mass_mag b2.vx += dx * b_mass_mag b2.vy += dy * b_mass_mag b2.vz += dz * b_mass_mag i += 1 end @x += dt * @vx @y += dt * @vy @z += dt * @vz end end def energy(bodies) e = 0.0 nbodies = bodies.size for i in 0 ... nbodies b = bodies[i] e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz) for j in (i + 1) ... nbodies b2 = bodies[j] dx = b.x - b2.x dy = b.y - b2.y dz = b.z - b2.z distance = Math.sqrt(dx * dx + dy * dy + dz * dz) e -= (b.mass * b2.mass) / distance end end e end def offset_momentum(bodies) px, py, pz = 0.0, 0.0, 0.0 for b in bodies m = b.mass px += b.vx * m py += b.vy * m pz += b.vz * m end b = bodies[0] b.vx = - px / SOLAR_MASS b.vy = - py / SOLAR_MASS b.vz = - pz / SOLAR_MASS end BODIES = [ # sun Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0), # jupiter Planet.new( 4.84143144246472090e+00, -1.16032004402742839e+00, -1.03622044471123109e-01, 1.66007664274403694e-03, 7.69901118419740425e-03, -6.90460016972063023e-05, 9.54791938424326609e-04), # saturn Planet.new( 8.34336671824457987e+00, 4.12479856412430479e+00, -4.03523417114321381e-01, -2.76742510726862411e-03, 4.99852801234917238e-03, 2.30417297573763929e-05, 2.85885980666130812e-04), # uranus Planet.new( 1.28943695621391310e+01, -1.51111514016986312e+01, -2.23307578892655734e-01, 2.96460137564761618e-03, 2.37847173959480950e-03, -2.96589568540237556e-05, 4.36624404335156298e-05), # neptune Planet.new( 1.53796971148509165e+01, -2.59193146099879641e+01, 1.79258772950371181e-01, 2.68067772490389322e-03, 1.62824170038242295e-03, -9.51592254519715870e-05, 5.15138902046611451e-05) ] init = 200_000 # ARGV[0] n = Integer(init) offset_momentum(BODIES) puts "%.9f" % energy(BODIES) nbodies = BODIES.size dt = 0.01 n.times do i = 0 while i < nbodies b = BODIES[i] b.move_from_i(BODIES, nbodies, dt, i + 1) i += 1 end end puts "%.9f" % energy(BODIES) trunk 3.51172184944153 trunk 3.61125087738037 trunk 3.62259292602539 trunk 3.65739679336548 trunk 3.59180092811584 trunk 3.6995050907135 trunk 3.74764394760132 trunk 3.53873991966248 trunk 3.6369149684906 trunk 3.63099718093872 rgengc 3.53772211074829 rgengc 3.56889915466309 rgengc 3.8447699546814 rgengc 3.56102108955383 rgengc 3.74757409095764 rgengc 3.52170991897583 rgengc 3.79700589179993 rgengc 3.78095889091492 rgengc 3.59943795204163 rgengc 3.50401592254639 ----------------------------------------------------------- so_nested_loop #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # from Avi Bryant n = 16 # Integer(ARGV.shift || 1) x = 0 n.times do n.times do n.times do n.times do n.times do n.times do x += 1 end end end end end end # puts x trunk 2.27585291862488 trunk 2.28183007240295 trunk 2.24824500083923 trunk 2.65239191055298 trunk 2.25976204872131 trunk 2.4017231464386 trunk 2.23868799209595 trunk 2.66950798034668 trunk 2.22815012931824 trunk 2.41493797302246 rgengc 2.24544191360474 rgengc 2.24904298782349 rgengc 2.25036787986755 rgengc 2.29263806343079 rgengc 2.3677830696106 rgengc 2.28724193572998 rgengc 2.32466793060303 rgengc 2.26726388931274 rgengc 2.29128408432007 rgengc 2.25364804267883 ----------------------------------------------------------- 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 4.47905302047729 trunk 4.3548641204834 trunk 4.41139984130859 trunk 4.38826894760132 trunk 4.54196190834045 trunk 4.5282289981842 trunk 4.4903712272644 trunk 4.40211510658264 trunk 4.37734198570251 trunk 4.51917004585266 rgengc 5.00994992256165 rgengc 4.45628094673157 rgengc 4.49591898918152 rgengc 4.48408198356628 rgengc 4.46144104003906 rgengc 4.50204682350159 rgengc 4.47356605529785 rgengc 4.48545503616333 rgengc 4.52476406097412 rgengc 4.63679003715515 ----------------------------------------------------------- so_nsieve_bits #!/usr/bin/ruby #coding: us-ascii # # The Great Computer Language Shootout # http://shootout.alioth.debian.org/ # # nsieve-bits in Ruby # Contributed by Glenn Parker, March 2005 CharExponent = 3 BitsPerChar = 1 << CharExponent LowMask = BitsPerChar - 1 def sieve(m) items = "\xFF" * ((m / BitsPerChar) + 1) masks = "" BitsPerChar.times do |b| masks << (1 << b).chr end count = 0 pmax = m - 1 2.step(pmax, 1) do |p| if items[p >> CharExponent][p & LowMask] == 1 count += 1 p.step(pmax, p) do |mult| a = mult >> CharExponent b = mult & LowMask items[a] -= masks[b] if items[a][b] != 0 end end end count end n = 9 # (ARGV[0] || 2).to_i n.step(n - 2, -1) do |exponent| break if exponent < 0 m = 2 ** exponent * 10_000 count = sieve(m) printf "Primes up to %8d %8d\n", m, count end trunk 4.74183297157288 trunk 4.56797194480896 trunk 4.63621306419373 trunk 4.94802212715149 trunk 4.70737290382385 trunk 4.61038899421692 trunk 4.68540596961975 trunk 4.67130994796753 trunk 4.55875420570374 trunk 4.5524730682373 rgengc 4.94371581077576 rgengc 4.71191620826721 rgengc 4.81243515014648 rgengc 4.86296200752258 rgengc 4.94525194168091 rgengc 4.86999583244324 rgengc 4.74149394035339 rgengc 4.72475790977478 rgengc 5.0347900390625 rgengc 4.7336859703064 ----------------------------------------------------------- so_object #!/usr/bin/ruby # -*- mode: ruby -*- # $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $ # http://www.bagley.org/~doug/shootout/ # with help from Aristarkh Zagorodnikov class Toggle def initialize(start_state) @bool = start_state end def value @bool end def activate @bool = !@bool self end end class NthToggle < Toggle def initialize(start_state, max_counter) super start_state @count_max = max_counter @counter = 0 end def activate @counter += 1 if @counter >= @count_max @bool = !@bool @counter = 0 end self end end n = 1500000 # (ARGV.shift || 1).to_i toggle = Toggle.new 1 5.times do toggle.activate.value ? 'true' : 'false' end n.times do toggle = Toggle.new 1 end ntoggle = NthToggle.new 1, 3 8.times do ntoggle.activate.value ? 'true' : 'false' end n.times do ntoggle = NthToggle.new 1, 3 end trunk 1.66079807281494 trunk 1.76995396614075 trunk 1.72539901733398 trunk 1.69928479194641 trunk 1.72709202766418 trunk 1.73095107078552 trunk 1.61893510818481 trunk 1.71127390861511 trunk 1.61957597732544 trunk 1.58398509025574 rgengc 1.73580312728882 rgengc 1.64608693122864 rgengc 1.68608283996582 rgengc 1.6721670627594 rgengc 1.66384887695312 rgengc 1.656653881073 rgengc 1.66965794563293 rgengc 1.65042781829834 rgengc 1.69239497184753 rgengc 1.67161297798157 ----------------------------------------------------------- so_partial_sums n = 2_500_000 # (ARGV.shift || 1).to_i alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0 1.upto(n) do |d| d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d) s0 += (2.0 / 3.0) ** (d - 1.0) s1 += 1.0 / Math.sqrt(d) s2 += 1.0 / (d * (d + 1.0)) s3 += 1.0 / (d3 * ds * ds) s4 += 1.0 / (d3 * dc * dc) s5 += 1.0 / d s6 += 1.0 / d2 s7 += alt / d s8 += alt / (2.0 * d - 1.0) alt = -alt end if false printf("%.9f\t(2/3)^k\n", s0) printf("%.9f\tk^-0.5\n", s1) printf("%.9f\t1/k(k+1)\n", s2) printf("%.9f\tFlint Hills\n", s3) printf("%.9f\tCookson Hills\n", s4) printf("%.9f\tHarmonic\n", s5) printf("%.9f\tRiemann Zeta\n", s6) printf("%.9f\tAlternating Harmonic\n", s7) printf("%.9f\tGregory\n", s8) end trunk 5.41891717910767 trunk 5.23819398880005 trunk 5.14459800720215 trunk 4.96550893783569 trunk 5.07959508895874 trunk 5.06756997108459 trunk 5.24095511436462 trunk 5.34584403038025 trunk 5.14200091362 trunk 5.21082186698914 rgengc 5.26118898391724 rgengc 5.18431901931763 rgengc 5.16091704368591 rgengc 5.17667984962463 rgengc 5.08632302284241 rgengc 5.235680103302 rgengc 5.12049293518066 rgengc 5.31076097488403 rgengc 5.37785792350769 rgengc 5.10467886924744 ----------------------------------------------------------- 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 1.67722392082214 trunk 1.67831301689148 trunk 1.68183994293213 trunk 1.67716598510742 trunk 1.68217086791992 trunk 1.67850613594055 trunk 1.68262386322021 trunk 1.67990207672119 trunk 1.67774200439453 trunk 1.68123316764832 rgengc 1.69009399414062 rgengc 1.69073700904846 rgengc 1.68876314163208 rgengc 1.69056010246277 rgengc 1.68737006187439 rgengc 1.69021797180176 rgengc 1.68724608421326 rgengc 1.69058299064636 rgengc 1.69457006454468 rgengc 1.68870282173157 ----------------------------------------------------------- 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 4.07404494285583 trunk 4.13849687576294 trunk 4.02996897697449 trunk 4.04739093780518 trunk 4.07706785202026 trunk 4.06683611869812 trunk 4.04404616355896 trunk 4.10937905311584 trunk 4.03965783119202 trunk 4.03941011428833 rgengc 4.03546500205994 rgengc 3.8656849861145 rgengc 3.8344669342041 rgengc 4.02979803085327 rgengc 3.85669088363647 rgengc 3.77218890190125 rgengc 3.98842000961304 rgengc 3.82667303085327 rgengc 3.86851906776428 rgengc 4.01301193237305 ----------------------------------------------------------- so_sieve # from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby num = 500 count = i = j = 0 flags0 = Array.new(8192,1) k = 0 while k < num k += 1 count = 0 flags = flags0.dup i = 2 while i<8192 i += 1 if flags[i] # remove all multiples of prime: i j = i*i while j < 8192 j += i flags[j] = nil end count += 1 end end end count trunk 1.52392601966858 trunk 1.51083302497864 trunk 1.50212407112122 trunk 1.4902720451355 trunk 1.55397796630859 trunk 1.49593687057495 trunk 1.78660917282104 trunk 1.51247906684875 trunk 1.51520204544067 trunk 1.51541590690613 rgengc 1.75697708129883 rgengc 1.58033680915833 rgengc 1.57139611244202 rgengc 1.55831098556519 rgengc 1.53006792068481 rgengc 1.53014898300171 rgengc 1.54720091819763 rgengc 1.70612788200378 rgengc 1.66095018386841 rgengc 1.54772305488586 ----------------------------------------------------------- so_spectralnorm # The Computer Language Shootout # http://shootout.alioth.debian.org/ # Contributed by Sokolov Yura def eval_A(i,j) return 1.0/((i+j)*(i+j+1)/2+i+1) end def eval_A_times_u(u) v, i = nil, nil (0..u.length-1).collect { |i| v = 0 for j in 0..u.length-1 v += eval_A(i,j)*u[j] end v } end def eval_At_times_u(u) v, i = nil, nil (0..u.length-1).collect{|i| v = 0 for j in 0..u.length-1 v += eval_A(j,i)*u[j] end v } end def eval_AtA_times_u(u) return eval_At_times_u(eval_A_times_u(u)) end n = 500 # ARGV[0].to_i u=[1]*n for i in 1..10 v=eval_AtA_times_u(u) u=eval_AtA_times_u(v) end vBv=0 vv=0 for i in 0..n-1 vBv += u[i]*v[i] vv += v[i]*v[i] end str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n" # print str trunk 4.82979202270508 trunk 4.86924004554749 trunk 4.87864398956299 trunk 4.9069881439209 trunk 4.85188603401184 trunk 4.91636204719543 trunk 4.66547107696533 trunk 4.91966509819031 trunk 5.01381206512451 trunk 4.96034097671509 rgengc 5.06122493743896 rgengc 4.60956692695618 rgengc 4.92073106765747 rgengc 5.39424395561218 rgengc 5.06470584869385 rgengc 5.46424007415771 rgengc 4.89115905761719 rgengc 4.95015501976013 rgengc 5.04717993736267 rgengc 5.43824195861816 ----------------------------------------------------------- vm1_array_append def foo ary = [] 100.times{|i| ary << i } end i=0 while i<300000 # while loop 1 i+=1 foo end trunk 4.67611289024353 trunk 4.67370009422302 trunk 4.78087401390076 trunk 4.66353702545166 trunk 4.65897703170776 trunk 4.63341212272644 trunk 4.67641186714172 trunk 4.90349888801575 trunk 4.67891311645508 trunk 4.6544349193573 rgengc 4.79456496238708 rgengc 4.83553600311279 rgengc 4.82544589042664 rgengc 5.23681211471558 rgengc 4.73335814476013 rgengc 4.74299001693726 rgengc 5.03413510322571 rgengc 4.74339985847473 rgengc 4.96029305458069 rgengc 4.86877512931824 ----------------------------------------------------------- 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 4.36401605606079 trunk 4.3629789352417 trunk 4.31383991241455 trunk 4.36354994773865 trunk 4.34842991828918 trunk 4.89697408676147 trunk 4.36277484893799 trunk 4.36277008056641 trunk 4.36262512207031 trunk 4.34839105606079 rgengc 3.73174500465393 rgengc 3.73372411727905 rgengc 3.73154401779175 rgengc 3.73383402824402 rgengc 3.73473405838013 rgengc 3.7420871257782 rgengc 3.71809506416321 rgengc 3.73397016525269 rgengc 4.06406092643738 rgengc 3.71767115592957 ----------------------------------------------------------- vm1_attr_ivar_set class C attr_accessor :a, :b def initialize @a = nil @b = nil end end obj = C.new i = 0 while i<30_000_000 # while loop 1 i += 1 obj.a = 1 obj.b = 2 end trunk 4.51609492301941 trunk 4.52310490608215 trunk 4.52532005310059 trunk 4.5143039226532 trunk 4.52218008041382 trunk 4.53102993965149 trunk 4.52208590507507 trunk 4.68988490104675 trunk 4.52232599258423 trunk 4.5218358039856 rgengc 4.74664092063904 rgengc 4.62587308883667 rgengc 4.16688013076782 rgengc 4.17588186264038 rgengc 4.92168211936951 rgengc 4.17429494857788 rgengc 4.25453400611877 rgengc 4.30496501922607 rgengc 4.18256998062134 rgengc 4.21246600151062 ----------------------------------------------------------- vm1_block def m yield end i = 0 while i<30_000_000 # while loop 1 i += 1 m{ } end trunk 4.31944608688354 trunk 4.10145592689514 trunk 4.28533482551575 trunk 4.15113997459412 trunk 4.23507308959961 trunk 4.37473678588867 trunk 4.27235889434814 trunk 4.17226195335388 trunk 4.53193306922913 trunk 4.73217296600342 rgengc 4.70381999015808 rgengc 4.69900608062744 rgengc 5.1546049118042 rgengc 5.78354692459106 rgengc 6.13307905197144 rgengc 5.18305516242981 rgengc 6.3740119934082 rgengc 6.19256687164307 rgengc 4.6575129032135 rgengc 5.80101895332336 ----------------------------------------------------------- vm1_const Const = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = Const k = Const end trunk 1.63885498046875 trunk 2.09410500526428 trunk 1.57113409042358 trunk 1.67409992218018 trunk 2.10303497314453 trunk 1.64014792442322 trunk 1.64355707168579 trunk 2.09029698371887 trunk 1.6453161239624 trunk 1.62167906761169 rgengc 3.04192900657654 rgengc 2.75460982322693 rgengc 3.04917883872986 rgengc 3.25161194801331 rgengc 2.73769116401672 rgengc 2.73776197433472 rgengc 3.03952813148499 rgengc 2.73972511291504 rgengc 2.7387318611145 rgengc 3.04467010498047 ----------------------------------------------------------- vm1_ensure i = 0 while i<30_000_000 # benchmark loop 1 i += 1 begin begin ensure end ensure end end trunk 1.23622703552246 trunk 1.23665595054626 trunk 1.23734092712402 trunk 1.24417781829834 trunk 1.23640584945679 trunk 1.24463701248169 trunk 1.23689889907837 trunk 1.2365128993988 trunk 1.23732304573059 trunk 1.24490308761597 rgengc 1.26190710067749 rgengc 1.26002597808838 rgengc 1.24744987487793 rgengc 1.2474308013916 rgengc 1.26806402206421 rgengc 1.83413910865784 rgengc 1.26782512664795 rgengc 1.24731516838074 rgengc 1.27040696144104 rgengc 1.25914096832275 ----------------------------------------------------------- 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 11.2181689739227 trunk 10.7595450878143 trunk 11.7437300682068 trunk 10.5825431346893 trunk 11.0045318603516 trunk 11.8961880207062 trunk 15.4307329654694 trunk 11.1933259963989 trunk 11.3630499839783 trunk 11.3417420387268 rgengc 10.2007060050964 rgengc 10.2914350032806 rgengc 11.7569320201874 rgengc 10.1105580329895 rgengc 10.6789870262146 rgengc 10.9181799888611 rgengc 10.1568109989166 rgengc 9.97093510627747 rgengc 11.2132160663605 rgengc 10.1955218315125 ----------------------------------------------------------- vm1_ivar @a = 1 i = 0 while i<30_000_000 # while loop 1 i += 1 j = @a k = @a end trunk 2.24964189529419 trunk 2.34442496299744 trunk 2.90373706817627 trunk 2.28578186035156 trunk 2.27193689346313 trunk 2.19934296607971 trunk 2.43638706207275 trunk 2.3398118019104 trunk 2.18845105171204 trunk 2.91842293739319 rgengc 3.68598699569702 rgengc 4.21514081954956 rgengc 4.34749603271484 rgengc 4.22998690605164 rgengc 3.68549108505249 rgengc 3.91128993034363 rgengc 4.2198531627655 rgengc 4.22207379341125 rgengc 3.68561983108521 rgengc 3.68542289733887 ----------------------------------------------------------- vm1_ivar_set i = 0 while i<30_000_000 # while loop 1 i += 1 @a = 1 @b = 2 end trunk 3.57970809936523 trunk 3.57963991165161 trunk 4.09166693687439 trunk 3.60499691963196 trunk 3.57954001426697 trunk 3.57956385612488 trunk 3.57971096038818 trunk 3.57936716079712 trunk 4.13623690605164 trunk 3.57944798469543 rgengc 4.15014100074768 rgengc 4.14133286476135 rgengc 4.10606598854065 rgengc 3.51960110664368 rgengc 3.59286999702454 rgengc 3.51972818374634 rgengc 3.54945397377014 rgengc 3.51959300041199 rgengc 3.55694007873535 rgengc 3.53920602798462 ----------------------------------------------------------- vm1_length a = 'abc' b = [1, 2, 3] i = 0 while i<30_000_000 # while loop 1 i += 1 a.length b.length end trunk 2.27531599998474 trunk 2.51603889465332 trunk 2.33152508735657 trunk 2.26782011985779 trunk 2.27987098693848 trunk 2.31399011611938 trunk 2.32660293579102 trunk 2.271164894104 trunk 2.28455305099487 trunk 2.26582384109497 rgengc 2.24144315719604 rgengc 2.24273180961609 rgengc 2.71174812316895 rgengc 2.31171989440918 rgengc 2.72268605232239 rgengc 2.71369791030884 rgengc 2.24434900283813 rgengc 2.24778604507446 rgengc 2.24116706848145 rgengc 2.21643209457397 ----------------------------------------------------------- vm1_length_original o = Object.new def o.length 0 end i=0 while i<30000000 # while loop 1 i+=1 o.length o.length end trunk 5.52342009544373 trunk 5.58455920219421 trunk 6.24548101425171 trunk 5.64297890663147 trunk 5.52785992622375 trunk 5.64214301109314 trunk 6.31604886054993 trunk 6.14720606803894 trunk 6.14899682998657 trunk 6.40789389610291 rgengc 7.26391792297363 rgengc 7.07577800750732 rgengc 5.76703000068665 rgengc 5.7113139629364 rgengc 5.73873782157898 rgengc 5.52301383018494 rgengc 5.63711595535278 rgengc 5.70683789253235 rgengc 7.07180094718933 rgengc 6.30320501327515 ----------------------------------------------------------- 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 6.02195811271667 trunk 4.94831991195679 trunk 4.93658399581909 trunk 5.32775616645813 trunk 4.95957183837891 trunk 4.91255021095276 trunk 4.89108109474182 trunk 4.96045804023743 trunk 6.02216386795044 trunk 4.96286702156067 rgengc 4.68581414222717 rgengc 5.26245403289795 rgengc 4.62432885169983 rgengc 4.69440698623657 rgengc 4.40134215354919 rgengc 5.35295391082764 rgengc 5.45947098731995 rgengc 4.40215301513672 rgengc 5.72899293899536 rgengc 4.64624881744385 ----------------------------------------------------------- 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 10.7685530185699 trunk 10.7830140590668 trunk 10.7975509166718 trunk 10.5749080181122 trunk 10.7476677894592 trunk 10.4312570095062 trunk 10.4344990253448 trunk 10.6592881679535 trunk 10.4121551513672 trunk 10.4451508522034 rgengc 11.337898015976 rgengc 11.1352710723877 rgengc 11.3725829124451 rgengc 11.2719619274139 rgengc 11.5291650295258 rgengc 11.1719789505005 rgengc 11.2708830833435 rgengc 11.0366668701172 rgengc 11.4827589988708 rgengc 11.4062230587006 ----------------------------------------------------------- vm1_neq i = 0 obj1 = Object.new obj2 = Object.new while i<30_000_000 # while loop 1 i += 1 obj1 != obj2 end trunk 2.0671181678772 trunk 2.08979105949402 trunk 2.08821105957031 trunk 2.02955603599548 trunk 2.11807990074158 trunk 2.07827401161194 trunk 2.06883907318115 trunk 2.59067010879517 trunk 2.03462696075439 trunk 3.15315198898315 rgengc 2.09975910186768 rgengc 3.06057214736938 rgengc 2.07887816429138 rgengc 2.09344077110291 rgengc 2.06645393371582 rgengc 2.10173487663269 rgengc 3.07033801078796 rgengc 2.08628702163696 rgengc 2.00024914741516 rgengc 2.47941708564758 ----------------------------------------------------------- vm1_not i = 0 obj = Object.new while i<30_000_000 # while loop 1 i += 1 !obj end trunk 1.5545380115509 trunk 1.56551003456116 trunk 1.57254195213318 trunk 1.55863809585571 trunk 1.55737090110779 trunk 1.58239579200745 trunk 1.54827284812927 trunk 1.58409094810486 trunk 1.53350496292114 trunk 1.55475783348083 rgengc 1.66590309143066 rgengc 2.62225985527039 rgengc 1.52494716644287 rgengc 1.52603912353516 rgengc 1.54777002334595 rgengc 1.52840304374695 rgengc 1.66808605194092 rgengc 1.53288006782532 rgengc 1.52500104904175 rgengc 1.64041113853455 ----------------------------------------------------------- vm1_rescue i = 0 while i<30_000_000 # while loop 1 i += 1 begin rescue end end trunk 1.2687828540802 trunk 1.25396490097046 trunk 1.25287699699402 trunk 1.25950503349304 trunk 1.25951409339905 trunk 1.25313997268677 trunk 1.25959801673889 trunk 1.2598819732666 trunk 1.25432896614075 trunk 1.81940913200378 rgengc 1.26407504081726 rgengc 1.27366590499878 rgengc 1.66672897338867 rgengc 1.67109608650208 rgengc 1.50186991691589 rgengc 1.28833794593811 rgengc 1.27308297157288 rgengc 1.2865879535675 rgengc 1.50137615203857 rgengc 1.26383590698242 ----------------------------------------------------------- vm1_simplereturn def m return 1 end i = 0 while i<30_000_000 # while loop 1 i += 1 m end trunk 2.48643779754639 trunk 2.60166001319885 trunk 2.45334005355835 trunk 2.7973690032959 trunk 2.81187295913696 trunk 2.49163317680359 trunk 2.4846031665802 trunk 2.62278485298157 trunk 2.96990704536438 trunk 2.9416229724884 rgengc 2.53945517539978 rgengc 2.48404693603516 rgengc 2.48405408859253 rgengc 2.49532389640808 rgengc 2.48356699943542 rgengc 2.58155298233032 rgengc 3.04415702819824 rgengc 2.48378896713257 rgengc 2.46924805641174 rgengc 2.48367810249329 ----------------------------------------------------------- vm1_swap a = 1 b = 2 i = 0 while i<30_000_000 # while loop 1 i += 1 a, b = b, a end trunk 1.41829299926758 trunk 1.41798615455627 trunk 1.41920614242554 trunk 1.41831207275391 trunk 1.41836190223694 trunk 1.4182140827179 trunk 1.43930196762085 trunk 1.41816091537476 trunk 1.41786813735962 trunk 1.41938185691833 rgengc 1.50005507469177 rgengc 1.50380396842957 rgengc 1.56824111938477 rgengc 1.50063800811768 rgengc 1.99056482315063 rgengc 1.53499698638916 rgengc 1.51172685623169 rgengc 1.66737294197083 rgengc 1.56779599189758 rgengc 1.50735187530518 ----------------------------------------------------------- vm1_yield def m i = 0 while i<30_000_000 # while loop 1 i += 1 yield end end m{} trunk 3.13813614845276 trunk 2.6746609210968 trunk 2.80433511734009 trunk 2.80851912498474 trunk 2.86332011222839 trunk 2.80354189872742 trunk 2.80420589447021 trunk 2.76431679725647 trunk 2.80903387069702 trunk 2.80094695091248 rgengc 3.37299013137817 rgengc 3.37734603881836 rgengc 3.36823511123657 rgengc 3.4417450428009 rgengc 3.76365208625793 rgengc 3.45042610168457 rgengc 3.29642295837402 rgengc 3.1904730796814 rgengc 3.39772391319275 rgengc 3.40261197090149 ----------------------------------------------------------- vm2_array i = 0 while i<6_000_000 # benchmark loop 2 i += 1 a = [1,2,3,4,5,6,7,8,9,10] end trunk 2.28778409957886 trunk 2.2805860042572 trunk 2.27787494659424 trunk 2.30439519882202 trunk 2.32402396202087 trunk 2.28689694404602 trunk 2.27969908714294 trunk 2.26496005058289 trunk 2.44131302833557 trunk 2.26926422119141 rgengc 2.26338505744934 rgengc 2.229407787323 rgengc 2.26197695732117 rgengc 2.34327793121338 rgengc 2.22826409339905 rgengc 2.23015689849854 rgengc 2.22950601577759 rgengc 2.36389803886414 rgengc 2.3340368270874 rgengc 2.26139497756958 ----------------------------------------------------------- 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 28.1910488605499 trunk 28.3015592098236 trunk 28.299595117569 trunk 28.4572911262512 trunk 28.2787930965424 trunk 28.2857799530029 trunk 28.471116065979 trunk 28.205188035965 trunk 28.3565359115601 trunk 28.2262511253357 rgengc 31.4872579574585 rgengc 31.4346330165863 rgengc 31.4987370967865 rgengc 31.3409948348999 rgengc 31.3956770896912 rgengc 31.2540609836578 rgengc 31.2994799613953 rgengc 31.3685700893402 rgengc 31.3175349235535 rgengc 31.3490319252014 ----------------------------------------------------------- vm2_bighash i = 0 while i<60_000 # benchmark loop 2 i += 1 a = {0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, 10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 19=>19, 20=>20, 21=>21, 22=>22, 23=>23, 24=>24, 25=>25, 26=>26, 27=>27, 28=>28, 29=>29, 30=>30, 31=>31, 32=>32, 33=>33, 34=>34, 35=>35, 36=>36, 37=>37, 38=>38, 39=>39, 40=>40, 41=>41, 42=>42, 43=>43, 44=>44, 45=>45, 46=>46, 47=>47, 48=>48, 49=>49, 50=>50, 51=>51, 52=>52, 53=>53, 54=>54, 55=>55, 56=>56, 57=>57, 58=>58, 59=>59, 60=>60, 61=>61, 62=>62, 63=>63, 64=>64, 65=>65, 66=>66, 67=>67, 68=>68, 69=>69, 70=>70, 71=>71, 72=>72, 73=>73, 74=>74, 75=>75, 76=>76, 77=>77, 78=>78, 79=>79, 80=>80, 81=>81, 82=>82, 83=>83, 84=>84, 85=>85, 86=>86, 87=>87, 88=>88, 89=>89, 90=>90, 91=>91, 92=>92, 93=>93, 94=>94, 95=>95, 96=>96, 97=>97, 98=>98, 99=>99, 100=>100, 101=>101, 102=>102, 103=>103, 104=>104, 105=>105, 106=>106, 107=>107, 108=>108, 109=>109, 110=>110, 111=>111, 112=>112, 113=>113, 114=>114, 115=>115, 116=>116, 117=>117, 118=>118, 119=>119, 120=>120, 121=>121, 122=>122, 123=>123, 124=>124, 125=>125, 126=>126, 127=>127, 128=>128, 129=>129, 130=>130, 131=>131, 132=>132, 133=>133, 134=>134, 135=>135, 136=>136, 137=>137, 138=>138, 139=>139, 140=>140, 141=>141, 142=>142, 143=>143, 144=>144, 145=>145, 146=>146, 147=>147, 148=>148, 149=>149, 150=>150, 151=>151, 152=>152, 153=>153, 154=>154, 155=>155, 156=>156, 157=>157, 158=>158, 159=>159, 160=>160, 161=>161, 162=>162, 163=>163, 164=>164, 165=>165, 166=>166, 167=>167, 168=>168, 169=>169, 170=>170, 171=>171, 172=>172, 173=>173, 174=>174, 175=>175, 176=>176, 177=>177, 178=>178, 179=>179, 180=>180, 181=>181, 182=>182, 183=>183, 184=>184, 185=>185, 186=>186, 187=>187, 188=>188, 189=>189, 190=>190, 191=>191, 192=>192, 193=>193, 194=>194, 195=>195, 196=>196, 197=>197, 198=>198, 199=>199, 200=>200, 201=>201, 202=>202, 203=>203, 204=>204, 205=>205, 206=>206, 207=>207, 208=>208, 209=>209, 210=>210, 211=>211, 212=>212, 213=>213, 214=>214, 215=>215, 216=>216, 217=>217, 218=>218, 219=>219, 220=>220, 221=>221, 222=>222, 223=>223, 224=>224, 225=>225, 226=>226, 227=>227, 228=>228, 229=>229, 230=>230, 231=>231, 232=>232, 233=>233, 234=>234, 235=>235, 236=>236, 237=>237, 238=>238, 239=>239, 240=>240, 241=>241, 242=>242, 243=>243, 244=>244, 245=>245, 246=>246, 247=>247, 248=>248, 249=>249, 250=>250, 251=>251, 252=>252, 253=>253, 254=>254, 255=>255, 256=>256, 257=>257, 258=>258, 259=>259, 260=>260, 261=>261, 262=>262, 263=>263, 264=>264, 265=>265, 266=>266, 267=>267, 268=>268, 269=>269, 270=>270, 271=>271, 272=>272, 273=>273, 274=>274, 275=>275, 276=>276, 277=>277, 278=>278, 279=>279, 280=>280, 281=>281, 282=>282, 283=>283, 284=>284, 285=>285, 286=>286, 287=>287, 288=>288, 289=>289, 290=>290, 291=>291, 292=>292, 293=>293, 294=>294, 295=>295, 296=>296, 297=>297, 298=>298, 299=>299, 300=>300, 301=>301, 302=>302, 303=>303, 304=>304, 305=>305, 306=>306, 307=>307, 308=>308, 309=>309, 310=>310, 311=>311, 312=>312, 313=>313, 314=>314, 315=>315, 316=>316, 317=>317, 318=>318, 319=>319, 320=>320, 321=>321, 322=>322, 323=>323, 324=>324, 325=>325, 326=>326, 327=>327, 328=>328, 329=>329, 330=>330, 331=>331, 332=>332, 333=>333, 334=>334, 335=>335, 336=>336, 337=>337, 338=>338, 339=>339, 340=>340, 341=>341, 342=>342, 343=>343, 344=>344, 345=>345, 346=>346, 347=>347, 348=>348, 349=>349, 350=>350, 351=>351, 352=>352, 353=>353, 354=>354, 355=>355, 356=>356, 357=>357, 358=>358, 359=>359, 360=>360, 361=>361, 362=>362, 363=>363, 364=>364, 365=>365, 366=>366, 367=>367, 368=>368, 369=>369, 370=>370, 371=>371, 372=>372, 373=>373, 374=>374, 375=>375, 376=>376, 377=>377, 378=>378, 379=>379, 380=>380, 381=>381, 382=>382, 383=>383, 384=>384, 385=>385, 386=>386, 387=>387, 388=>388, 389=>389, 390=>390, 391=>391, 392=>392, 393=>393, 394=>394, 395=>395, 396=>396, 397=>397, 398=>398, 399=>399, 400=>400, 401=>401, 402=>402, 403=>403, 404=>404, 405=>405, 406=>406, 407=>407, 408=>408, 409=>409, 410=>410, 411=>411, 412=>412, 413=>413, 414=>414, 415=>415, 416=>416, 417=>417, 418=>418, 419=>419, 420=>420, 421=>421, 422=>422, 423=>423, 424=>424, 425=>425, 426=>426, 427=>427, 428=>428, 429=>429, 430=>430, 431=>431, 432=>432, 433=>433, 434=>434, 435=>435, 436=>436, 437=>437, 438=>438, 439=>439, 440=>440, 441=>441, 442=>442, 443=>443, 444=>444, 445=>445, 446=>446, 447=>447, 448=>448, 449=>449, 450=>450, 451=>451, 452=>452, 453=>453, 454=>454, 455=>455, 456=>456, 457=>457, 458=>458, 459=>459, 460=>460, 461=>461, 462=>462, 463=>463, 464=>464, 465=>465, 466=>466, 467=>467, 468=>468, 469=>469, 470=>470, 471=>471, 472=>472, 473=>473, 474=>474, 475=>475, 476=>476, 477=>477, 478=>478, 479=>479, 480=>480, 481=>481, 482=>482, 483=>483, 484=>484, 485=>485, 486=>486, 487=>487, 488=>488, 489=>489, 490=>490, 491=>491, 492=>492, 493=>493, 494=>494, 495=>495, 496=>496, 497=>497, 498=>498, 499=>499, 500=>500,} end trunk 13.8457999229431 trunk 14.2571659088135 trunk 13.9512898921967 trunk 13.8795919418335 trunk 13.8394639492035 trunk 13.8543269634247 trunk 13.8479318618774 trunk 13.8783140182495 trunk 13.8531429767609 trunk 13.8880059719086 rgengc 13.8269209861755 rgengc 13.9584131240845 rgengc 13.9511640071869 rgengc 13.8520991802216 rgengc 14.0928409099579 rgengc 13.8661720752716 rgengc 14.0269830226898 rgengc 13.9227929115295 rgengc 13.913519859314 rgengc 13.9161820411682 ----------------------------------------------------------- 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.476272106170654 trunk 0.475473165512085 trunk 0.479724168777466 trunk 0.474663972854614 trunk 0.47779107093811 trunk 0.47549295425415 trunk 0.479218006134033 trunk 0.501480102539062 trunk 0.479771137237549 trunk 0.472181081771851 rgengc 0.584118127822876 rgengc 0.483380079269409 rgengc 0.470167875289917 rgengc 0.476732969284058 rgengc 0.479079961776733 rgengc 0.602834939956665 rgengc 0.476855993270874 rgengc 0.626279830932617 rgengc 0.469069004058838 rgengc 0.489008903503418 ----------------------------------------------------------- vm2_defined_method class Object define_method(:m){} end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m; m; m; m; m; m; m; m; end trunk 6.40461206436157 trunk 6.58256196975708 trunk 6.56539797782898 trunk 6.8047890663147 trunk 6.41538405418396 trunk 7.51800680160522 trunk 7.39271712303162 trunk 6.45685911178589 trunk 6.64817214012146 trunk 6.41504406929016 rgengc 6.31538701057434 rgengc 6.2935950756073 rgengc 6.42081308364868 rgengc 6.50126099586487 rgengc 6.3541100025177 rgengc 6.38390183448792 rgengc 6.53615498542786 rgengc 6.33389592170715 rgengc 6.333909034729 rgengc 6.51484799385071 ----------------------------------------------------------- vm2_dstr i = 0 x = y = 'z' while i<6_000_000 # benchmark loop 2 i += 1 str = "foo#{x}bar#{y}baz" end trunk 3.19676113128662 trunk 3.52381300926208 trunk 3.48882985115051 trunk 3.5632951259613 trunk 3.57543706893921 trunk 3.40660810470581 trunk 3.37521386146545 trunk 3.32959198951721 trunk 3.17921113967896 trunk 3.53021097183228 rgengc 3.49586200714111 rgengc 3.5109589099884 rgengc 3.49343204498291 rgengc 3.50093102455139 rgengc 3.5300989151001 rgengc 3.52048587799072 rgengc 3.57292699813843 rgengc 3.49520015716553 rgengc 3.56884694099426 rgengc 3.4889600276947 ----------------------------------------------------------- vm2_eval i = 0 while i<6_000_000 # benchmark loop 2 i += 1 eval("1") end trunk 50.4347369670868 trunk 50.2332019805908 trunk 50.2251920700073 trunk 50.5925359725952 trunk 50.5478870868683 trunk 49.8729128837585 trunk 49.893639087677 trunk 50.1680419445038 trunk 50.5006930828094 trunk 50.1766710281372 rgengc 43.0445249080658 rgengc 43.1012580394745 rgengc 42.3316698074341 rgengc 42.5367419719696 rgengc 42.4852411746979 rgengc 42.4396817684174 rgengc 43.1102130413055 rgengc 42.635883808136 rgengc 42.7061648368835 rgengc 42.2589089870453 ----------------------------------------------------------- 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 2.78573298454285 trunk 2.71945905685425 trunk 2.77758288383484 trunk 2.68032097816467 trunk 2.59406304359436 trunk 2.67267394065857 trunk 2.64110016822815 trunk 2.75225806236267 trunk 2.65013599395752 trunk 2.70922207832336 rgengc 2.69329500198364 rgengc 2.46208310127258 rgengc 2.83135914802551 rgengc 2.60770392417908 rgengc 2.46883988380432 rgengc 2.67759394645691 rgengc 2.61388182640076 rgengc 2.58394408226013 rgengc 2.45817899703979 rgengc 2.4727931022644 ----------------------------------------------------------- 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 4.3115541934967 trunk 4.31976699829102 trunk 4.25114488601685 trunk 4.45617699623108 trunk 4.59307980537415 trunk 4.42117285728455 trunk 4.42031002044678 trunk 4.51715517044067 trunk 4.50883889198303 trunk 4.68272113800049 rgengc 4.33715796470642 rgengc 4.22533512115479 rgengc 4.36543989181519 rgengc 4.34461903572083 rgengc 4.27077889442444 rgengc 4.43574285507202 rgengc 4.37628507614136 rgengc 4.31718897819519 rgengc 4.36625599861145 rgengc 4.39899206161499 ----------------------------------------------------------- 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 2.99001693725586 trunk 2.98012089729309 trunk 3.01071214675903 trunk 3.61456513404846 trunk 3.02079200744629 trunk 3.00662398338318 trunk 2.92701101303101 trunk 3.02769589424133 trunk 3.02746605873108 trunk 2.90126514434814 rgengc 3.13328409194946 rgengc 3.01908397674561 rgengc 2.93733906745911 rgengc 3.14147114753723 rgengc 2.9065318107605 rgengc 3.16231679916382 rgengc 2.97553491592407 rgengc 3.00958299636841 rgengc 3.05448293685913 rgengc 3.15049910545349 ----------------------------------------------------------- vm2_mutex require 'thread' m = Mutex.new i = 0 while i<6_000_000 # benchmark loop 2 i += 1 m.synchronize{} end trunk 2.13093495368958 trunk 2.08449006080627 trunk 2.37102484703064 trunk 2.18141007423401 trunk 2.15854287147522 trunk 2.35575413703918 trunk 2.32951307296753 trunk 2.17071986198425 trunk 2.10989189147949 trunk 2.13231897354126 rgengc 2.1045229434967 rgengc 2.10844302177429 rgengc 2.21687412261963 rgengc 2.14004588127136 rgengc 2.10881018638611 rgengc 2.09982991218567 rgengc 2.10400080680847 rgengc 2.30308699607849 rgengc 2.10447216033936 rgengc 2.13016796112061 ----------------------------------------------------------- vm2_poly_method class C1 def m 1 end end class C2 def m 2 end end o1 = C1.new o2 = C2.new i = 0 while i<6_000_000 # benchmark loop 2 o = (i % 2 == 0) ? o1 : o2 o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i += 1 end trunk 4.37502598762512 trunk 4.55363416671753 trunk 4.84148597717285 trunk 4.29042291641235 trunk 4.39802503585815 trunk 4.47798418998718 trunk 4.27922201156616 trunk 4.77777290344238 trunk 4.56724405288696 trunk 4.32463216781616 rgengc 4.4248321056366 rgengc 4.44708919525146 rgengc 5.68110203742981 rgengc 4.59005689620972 rgengc 4.55021691322327 rgengc 5.01849007606506 rgengc 4.98646402359009 rgengc 4.59452104568481 rgengc 4.45308089256287 rgengc 4.37967395782471 ----------------------------------------------------------- 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.625356912612915 trunk 0.618021011352539 trunk 0.673669099807739 trunk 0.673607110977173 trunk 0.628031969070435 trunk 0.669090032577515 trunk 0.635785818099976 trunk 0.628457069396973 trunk 0.616663932800293 trunk 0.62562108039856 rgengc 0.599634885787964 rgengc 0.641345977783203 rgengc 0.850876092910767 rgengc 0.617716073989868 rgengc 0.855133056640625 rgengc 0.725919008255005 rgengc 0.788821935653687 rgengc 0.629354000091553 rgengc 0.60503888130188 rgengc 0.611867189407349 ----------------------------------------------------------- vm2_proc def m &b b end pr = m{ a = 1 } i = 0 while i<6_000_000 # benchmark loop 2 i += 1 pr.call end trunk 1.16106009483337 trunk 1.16691613197327 trunk 1.17308211326599 trunk 1.16459393501282 trunk 1.19380807876587 trunk 1.16389894485474 trunk 1.16559600830078 trunk 1.19267392158508 trunk 1.17857193946838 trunk 1.20783996582031 rgengc 1.19758009910583 rgengc 1.16779017448425 rgengc 1.20109105110168 rgengc 1.20934200286865 rgengc 1.2328360080719 rgengc 1.18181395530701 rgengc 1.20362901687622 rgengc 1.20737504959106 rgengc 1.20232605934143 rgengc 1.21120190620422 ----------------------------------------------------------- vm2_raise1 def rec n if n > 0 rec n-1 else raise end end i = 0 while i<6_000_000 # benchmark loop 2 i += 1 begin rec 1 rescue # ignore end end trunk 15.4487700462341 trunk 15.1622061729431 trunk 15.4178020954132 trunk 15.1356620788574 trunk 15.1559610366821 trunk 14.6780250072479 trunk 15.0325989723206 trunk 15.0423910617828 trunk 15.3053209781647 trunk 14.7583441734314 rgengc 14.7886710166931 rgengc 14.7047579288483 rgengc 14.729220867157 rgengc 14.9943790435791 rgengc 14.9666569232941 rgengc 15.2041490077972 rgengc 14.9801790714264 rgengc 14.3690438270569 rgengc 14.6603009700775 rgengc 14.9413990974426 ----------------------------------------------------------- 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 22.915335893631 trunk 22.0695829391479 trunk 22.3940331935883 trunk 21.9323818683624 trunk 21.1691238880157 trunk 21.445965051651 trunk 21.8730680942535 trunk 20.8156578540802 trunk 21.4807569980621 trunk 20.6870641708374 rgengc 21.059916973114 rgengc 20.6819679737091 rgengc 21.2750480175018 rgengc 21.0788390636444 rgengc 22.0031991004944 rgengc 22.7791969776154 rgengc 20.8218469619751 rgengc 22.590313911438 rgengc 24.001100063324 rgengc 20.9794669151306 ----------------------------------------------------------- vm2_regexp i = 0 str = 'xxxhogexxx' while i<6_000_000 # benchmark loop 2 /hoge/ =~ str i += 1 end trunk 2.62284994125366 trunk 2.63280916213989 trunk 2.6304612159729 trunk 2.61292910575867 trunk 2.6207001209259 trunk 2.62519812583923 trunk 2.62053489685059 trunk 2.62931489944458 trunk 2.63052582740784 trunk 2.60719895362854 rgengc 2.67665600776672 rgengc 2.68546390533447 rgengc 2.67209219932556 rgengc 2.75175094604492 rgengc 2.66793584823608 rgengc 2.67481279373169 rgengc 2.65728998184204 rgengc 2.67204904556274 rgengc 2.67815399169922 rgengc 2.6824061870575 ----------------------------------------------------------- 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.835602998733521 trunk 0.807533979415894 trunk 0.810467004776001 trunk 0.923308849334717 trunk 0.814964056015015 trunk 0.820405006408691 trunk 0.810763120651245 trunk 0.808859825134277 trunk 0.812665224075317 trunk 0.834456920623779 rgengc 0.806572914123535 rgengc 0.810615062713623 rgengc 0.833634853363037 rgengc 0.806577920913696 rgengc 0.806777000427246 rgengc 0.920769929885864 rgengc 0.806761980056763 rgengc 0.806571960449219 rgengc 0.806681871414185 rgengc 0.81519889831543 ----------------------------------------------------------- vm2_super class C def m 1 end end class CC < C def m super() end end obj = CC.new i = 0 while i<6_000_000 # benchmark loop 2 obj.m i += 1 end trunk 1.1488618850708 trunk 1.10506701469421 trunk 1.08680987358093 trunk 1.0642421245575 trunk 1.15537095069885 trunk 1.01932501792908 trunk 1.13105487823486 trunk 1.14073896408081 trunk 1.17693090438843 trunk 1.12161707878113 rgengc 1.11458587646484 rgengc 1.10133194923401 rgengc 1.31642198562622 rgengc 1.18351697921753 rgengc 1.45706105232239 rgengc 1.25075197219849 rgengc 1.19349980354309 rgengc 1.27566599845886 rgengc 1.37053084373474 rgengc 1.09531497955322 ----------------------------------------------------------- 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.534398078918457 trunk 0.637417078018188 trunk 0.53118109703064 trunk 0.542521953582764 trunk 0.560328006744385 trunk 0.53527307510376 trunk 0.536664009094238 trunk 0.546205997467041 trunk 0.543935060501099 trunk 0.549074172973633 rgengc 0.634778022766113 rgengc 0.543287038803101 rgengc 0.740154981613159 rgengc 0.632963180541992 rgengc 0.666745185852051 rgengc 0.779426097869873 rgengc 0.569622993469238 rgengc 0.661429882049561 rgengc 0.559296131134033 rgengc 0.658504009246826 ----------------------------------------------------------- vm2_zsuper i = 0 class C def m a 1 end end class CC < C def m a super end end obj = CC.new while i<6_000_000 # benchmark loop 2 obj.m 10 i += 1 end trunk 1.10137605667114 trunk 1.08107209205627 trunk 1.18434810638428 trunk 1.04579210281372 trunk 1.12907886505127 trunk 1.24637794494629 trunk 1.06431317329407 trunk 1.04905915260315 trunk 1.08475494384766 trunk 1.20716309547424 rgengc 1.51255893707275 rgengc 1.36329507827759 rgengc 1.46110105514526 rgengc 1.53801298141479 rgengc 1.50925493240356 rgengc 1.37566804885864 rgengc 1.26954984664917 rgengc 1.45093202590942 rgengc 1.5388491153717 rgengc 1.33315515518188 ----------------------------------------------------------- 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.43605899810791 trunk 0.434023857116699 trunk 0.435509920120239 trunk 0.435956954956055 trunk 0.435672044754028 trunk 0.434412002563477 trunk 0.436048030853271 trunk 0.433827877044678 trunk 0.435863971710205 trunk 0.434437990188599 rgengc 0.433876991271973 rgengc 0.433175086975098 rgengc 0.435648918151855 rgengc 0.432056903839111 rgengc 0.434981107711792 rgengc 0.434598922729492 rgengc 0.434207201004028 rgengc 0.432775974273682 rgengc 0.4356369972229 rgengc 0.43855094909668 ----------------------------------------------------------- vm3_clearmethodcache i = 0 while i<200_000 i += 1 Class.new{ def m; end } end trunk 1.4885950088501 trunk 1.49670600891113 trunk 1.50667095184326 trunk 1.4812388420105 trunk 1.47520899772644 trunk 1.51320695877075 trunk 1.51067090034485 trunk 1.5116810798645 trunk 1.49119997024536 trunk 1.48186922073364 rgengc 1.11205697059631 rgengc 1.3902440071106 rgengc 1.11684203147888 rgengc 1.37324404716492 rgengc 1.39002799987793 rgengc 1.38961696624756 rgengc 1.34075808525085 rgengc 1.36406993865967 rgengc 1.39113998413086 rgengc 1.33791089057922 ----------------------------------------------------------- vm3_gc #! /usr/bin/ruby 5000.times do 100.times do {"xxxx"=>"yyyy"} end GC.start end trunk 4.36870384216309 trunk 4.30532193183899 trunk 4.32366681098938 trunk 4.26726102828979 trunk 4.39540696144104 trunk 4.32334589958191 trunk 4.3451361656189 trunk 4.3654510974884 trunk 4.33317804336548 trunk 4.36500120162964 rgengc 4.26519107818604 rgengc 4.29228091239929 rgengc 4.23081207275391 rgengc 4.26029205322266 rgengc 4.33991003036499 rgengc 4.19845986366272 rgengc 4.22219109535217 rgengc 4.24822998046875 rgengc 4.34791207313538 rgengc 4.19393491744995 ----------------------------------------------------------- vm3_thread_mutex exit require 'thread' m = Mutex.new r = 0 max = 1000 (1..max).map{ Thread.new{ i=0 while i