about summary refs log tree commit homepage
path: root/vm_method.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-01-27 06:57:35 +0000
committerEric Wong <e@80x24.org>2014-01-27 07:00:27 +0000
commita899e54e6abc13b8816e6c5f69ff560918db4be1 (patch)
treea58f7eebcd230352abe9c31d086ab21b234621db /vm_method.c
parent8d126e9e2929e6962a4fcf80bfc4b9b49a404923 (diff)
downloadruby-a899e54e6abc1.tar.gz
vm_method: cleanup method cache disabling nomethodcache
Performance without method cache really isn't bad without
method cache:

target 0: ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux] at "ruby --disable=gems"
target 1: built-ruby (ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]) at "./ruby -I./lib -I. -I.ext/common --disable-gems"

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.069115958
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.06926997
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.06921102
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.069450381
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.06918108
built-ruby	0.07046214
built-ruby	0.071342715
built-ruby	0.071297448
built-ruby	0.071299547
built-ruby	0.071684754

-----------------------------------------------------------
app_aobench

IMAGE_WIDTH = 256
IMAGE_HEIGHT = 256
NSUBSAMPLES = 2
NAO_SAMPLES = 8

class Vec
  def initialize(x, y, z)
    @x = x
    @y = y
    @z = z
  end

  attr_accessor :x, :y, :z

  def vadd(b)
    Vec.new(@x + b.x, @y + b.y, @z + b.z)
  end

  def vsub(b)
    Vec.new(@x - b.x, @y - b.y, @z - b.z)
  end

  def vcross(b)
    Vec.new(@y * b.z - @z * b.y,
            @z * b.x - @x * b.z,
            @x * b.y - @y * b.x)
  end

  def vdot(b)
    @x * b.x + @y * b.y + @z * b.z
  end

  def vlength
    Math.sqrt(@x * @x + @y * @y + @z * @z)
  end

  def vnormalize
    len = vlength
    v = Vec.new(@x, @y, @z)
    if len > 1.0e-17 then
      v.x = v.x / len
      v.y = v.y / len
      v.z = v.z / len
    end
    v
  end
end

class Sphere
  def initialize(center, radius)
    @center = center
    @radius = radius
  end

  attr_reader :center, :radius

  def intersect(ray, isect)
    rs = ray.org.vsub(@center)
    b = rs.vdot(ray.dir)
    c = rs.vdot(rs) - (@radius * @radius)
    d = b * b - c
    if d > 0.0 then
      t = - b - Math.sqrt(d)

      if t > 0.0 and t < isect.t then
        isect.t = t
        isect.hit = true
        isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
                          ray.org.y + ray.dir.y * t,
                          ray.org.z + ray.dir.z * t)
        n = isect.pl.vsub(@center)
        isect.n = n.vnormalize
      else
        0.0
      end
    end
    nil
  end
end

class Plane
  def initialize(p, n)
    @p = p
    @n = n
  end

  def intersect(ray, isect)
    d = -@p.vdot(@n)
    v = ray.dir.vdot(@n)
    v0 = v
    if v < 0.0 then
      v0 = -v
    end
    if v0 < 1.0e-17 then
      return
    end

    t = -(ray.org.vdot(@n) + d) / v

    if t > 0.0 and t < isect.t then
      isect.hit = true
      isect.t = t
      isect.n = @n
      isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
                        ray.org.y + t * ray.dir.y,
                        ray.org.z + t * ray.dir.z)
    end
    nil
  end
end

class Ray
  def initialize(org, dir)
    @org = org
    @dir = dir
  end

  attr_accessor :org, :dir
end

class Isect
  def initialize
    @t = 10000000.0
    @hit = false
    @pl = Vec.new(0.0, 0.0, 0.0)
    @n = Vec.new(0.0, 0.0, 0.0)
  end

  attr_accessor :t, :hit, :pl, :n
end

def clamp(f)
  i = f * 255.5
  if i > 255.0 then
    i = 255.0
  end
  if i < 0.0 then
    i = 0.0
  end
  i.to_i
end

def otherBasis(basis, n)
  basis[2] = Vec.new(n.x, n.y, n.z)
  basis[1] = Vec.new(0.0, 0.0, 0.0)

  if n.x < 0.6 and n.x > -0.6 then
    basis[1].x = 1.0
  elsif n.y < 0.6 and n.y > -0.6 then
    basis[1].y = 1.0
  elsif n.z < 0.6 and n.z > -0.6 then
    basis[1].z = 1.0
  else
    basis[1].x = 1.0
  end

  basis[0] = basis[1].vcross(basis[2])
  basis[0] = basis[0].vnormalize

  basis[1] = basis[2].vcross(basis[0])
  basis[1] = basis[1].vnormalize
end

class Scene
  def initialize
    @spheres = Array.new
    @spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5)
    @spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5)
    @spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5)
    @plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0))
  end

  def ambient_occlusion(isect)
    basis = Array.new
    otherBasis(basis, isect.n)

    ntheta    = NAO_SAMPLES
    nphi      = NAO_SAMPLES
    eps       = 0.0001
    occlusion = 0.0

    p0 = Vec.new(isect.pl.x + eps * isect.n.x,
                isect.pl.y + eps * isect.n.y,
                isect.pl.z + eps * isect.n.z)
    nphi.times do |j|
      ntheta.times do |i|
        r = rand
        phi = 2.0 * 3.14159265 * rand
        x = Math.cos(phi) * Math.sqrt(1.0 - r)
        y = Math.sin(phi) * Math.sqrt(1.0 - r)
        z = Math.sqrt(r)

        rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
        ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
        rz = x * basis[0].z + y * basis[1].z + z * basis[2].z

        raydir = Vec.new(rx, ry, rz)
        ray = Ray.new(p0, raydir)

        occisect = Isect.new
        @spheres[0].intersect(ray, occisect)
        @spheres[1].intersect(ray, occisect)
        @spheres[2].intersect(ray, occisect)
        @plane.intersect(ray, occisect)
        if occisect.hit then
          occlusion = occlusion + 1.0
        else
          0.0
        end
      end
    end

    occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f)

    Vec.new(occlusion, occlusion, occlusion)
  end

  def render(w, h, nsubsamples)
    cnt = 0
    nsf = nsubsamples.to_f
    h.times do |y|
      w.times do |x|
        rad = Vec.new(0.0, 0.0, 0.0)

        # Subsmpling
        nsubsamples.times do |v|
          nsubsamples.times do |u|

            cnt = cnt + 1
            wf = w.to_f
            hf = h.to_f
            xf = x.to_f
            yf = y.to_f
            uf = u.to_f
            vf = v.to_f

            px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
            py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)

            eye = Vec.new(px, py, -1.0).vnormalize

            ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)

            isect = Isect.new
            @spheres[0].intersect(ray, isect)
            @spheres[1].intersect(ray, isect)
            @spheres[2].intersect(ray, isect)
            @plane.intersect(ray, isect)
            if isect.hit then
              col = ambient_occlusion(isect)
              rad.x = rad.x + col.x
              rad.y = rad.y + col.y
              rad.z = rad.z + col.z
            end
          end
        end

        r = rad.x / (nsf * nsf)
        g = rad.y / (nsf * nsf)
        b = rad.z / (nsf * nsf)
        printf("%c", clamp(r))
        printf("%c", clamp(g))
        printf("%c", clamp(b))
      end
      nil
    end

    nil
  end
end

alias printf_orig printf
def printf *args
end

  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)

undef printf
alias printf printf_orig

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	82.528179264
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	86.038767054
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	83.955373562
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	83.931281878
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	83.744656236
built-ruby	86.047444711
built-ruby	86.970111775
built-ruby	86.703384838
built-ruby	85.086941462
built-ruby	87.40537543

-----------------------------------------------------------
app_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__

<html>
  <head> <%= title %> </head>
  <body>
    <h1> <%= title %> </h1>
    <p>
      <%= content %>
    </p>
  </body>
</html>

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.46321774
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.471494815
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.474278595
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.485722449
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.467138188
built-ruby	1.533831156
built-ruby	1.523069245
built-ruby	1.520039886
built-ruby	1.517973937
built-ruby	1.516723692

-----------------------------------------------------------
app_factorial

def fact(n)
  if(n > 1)
    n * fact(n-1)
  else
    1
  end
end

100.times {
  fact(5000)
}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.368356244
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.371527404
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.355026275
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.348838127
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.354984164
built-ruby	1.340291532
built-ruby	1.339430568
built-ruby	1.345734561
built-ruby	1.338615726
built-ruby	1.345918855

-----------------------------------------------------------
app_fib

def fib n
  if n < 3
    1
  else
    fib(n-1) + fib(n-2)
  end
end

fib(34)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.837208189
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.833599869
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.833381765
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.832548653
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.83341986
built-ruby	0.836904428
built-ruby	0.841274597
built-ruby	0.840583958
built-ruby	0.841151469
built-ruby	0.967884473

-----------------------------------------------------------
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)
  }
}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.800706663
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.749651764
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.747574821
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.782274642
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.745952519
built-ruby	2.283323719
built-ruby	2.279653605
built-ruby	2.273155713
built-ruby	2.327998505
built-ruby	2.250825736

-----------------------------------------------------------
app_pentomino

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__

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)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	24.296385154
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	24.38995728
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	24.177945801
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	24.380250106
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	24.188389453
built-ruby	24.370961852
built-ruby	24.416938988
built-ruby	24.440741607
built-ruby	24.532772735
built-ruby	24.538908662

-----------------------------------------------------------
app_raise

i = 0
while i<300000
  i += 1
  begin
    raise
  rescue
  end
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.492213775
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.492685653
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.493051224
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.488393417
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.485406938
built-ruby	0.615535319
built-ruby	0.609878188
built-ruby	0.602776171
built-ruby	0.601432916
built-ruby	0.600821616

-----------------------------------------------------------
app_strconcat

i = 0
while i<2_000_000
  "#{1+1} #{1+1} #{1+1}"
  i += 1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.579476486
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.598758991
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.603527045
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.627146082
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.603781493
built-ruby	1.744377507
built-ruby	1.773091946
built-ruby	1.800217493
built-ruby	1.759609869
built-ruby	1.749171655

-----------------------------------------------------------
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)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.106726826
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.177076003
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.110256736
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.110182835
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.107473709
built-ruby	1.235649576
built-ruby	1.233945608
built-ruby	1.240364787
built-ruby	1.156158583
built-ruby	1.21089341

-----------------------------------------------------------
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)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.917232531
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.903223315
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.893586256
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.894859441
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.895607827
built-ruby	0.966387685
built-ruby	0.980843355
built-ruby	0.934894547
built-ruby	0.907297411
built-ruby	0.963007847

-----------------------------------------------------------
app_uri

require 'uri'

100_000.times{
  uri = URI.parse('http://www.ruby-lang.org')
  uri.scheme
  uri.host
  uri.port
}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.099568786
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.082000754
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.081822547
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.076911935
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.087471019
built-ruby	1.156177298
built-ruby	1.160693997
built-ruby	1.155310872
built-ruby	1.154901146
built-ruby	1.139590661

-----------------------------------------------------------
hash_flatten

h = {}

10000.times do |i|
  h[i] = nil
end

1000.times do
  h.flatten
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.902394802
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.884952246
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.887560944
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.881342081
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.879146229
built-ruby	0.873058744
built-ruby	0.874640084
built-ruby	0.877583221
built-ruby	0.872320747
built-ruby	0.876329697

-----------------------------------------------------------
hash_keys

h = {}

10000.times do |i|
  h[i] = nil
end

5000.times do
  h.keys
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.397029458
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.407694535
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.400637665
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.400234933
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.402138458
built-ruby	0.402534751
built-ruby	0.410476245
built-ruby	0.405091748
built-ruby	0.396720909
built-ruby	0.399763643

-----------------------------------------------------------
hash_shift

h = {}

10000.times do |i|
  h[i] = nil
end

50000.times do
  k, v = h.shift
  h[k] = v
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.037129663
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.036840547
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.036222653
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.036399887
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.037119105
built-ruby	0.038616534
built-ruby	0.03931956
built-ruby	0.038513296
built-ruby	0.038836303
built-ruby	0.038827658

-----------------------------------------------------------
hash_values

h = {}

10000.times do |i|
  h[i] = nil
end

5000.times do
  h.values
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.406103511
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.404399534
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.408950118
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.408736098
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.407261318
built-ruby	0.402660006
built-ruby	0.408974861
built-ruby	0.40790732
built-ruby	0.405073422
built-ruby	0.401911494

-----------------------------------------------------------
io_file_create

max = 200_000
file = './tmpfile_of_bm_io_file_create'

max.times{
  f = open(file, 'w')
  f.close#(true)
}
File.unlink(file)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.352278127
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.307616344
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.328492224
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.328006981
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.339089271
built-ruby	1.538196822
built-ruby	1.513475723
built-ruby	1.486812243
built-ruby	1.530780153
built-ruby	1.528907202

-----------------------------------------------------------
io_file_read

require 'tempfile'

max = 200_000
str = "Hello world!  " * 1000
f = Tempfile.new('yarv-benchmark')
f.write str

max.times{
  f.seek 0
  f.read
}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.347668338
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.256763758
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.281661785
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.240669561
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.322793482
built-ruby	2.248574806
built-ruby	2.248717567
built-ruby	2.259497669
built-ruby	2.305376805
built-ruby	2.245098167

-----------------------------------------------------------
io_file_write

require 'tempfile'

max = 200_000
str = "Hello world!  " * 1000
f = Tempfile.new('yarv-benchmark')

max.times{
  f.seek 0
  f.write str
}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.217298688
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.180208878
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.15500956
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.178688551
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.190234321
built-ruby	1.217829388
built-ruby	1.241709339
built-ruby	1.228997633
built-ruby	1.183735168
built-ruby	1.226485586

-----------------------------------------------------------
io_select

w = [ IO.pipe[1] ];

nr = 1000000
nr.times {
  IO.select nil, w
}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.104997937
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.121240421
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.997004746
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.002810271
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.02273593
built-ruby	1.955583178
built-ruby	2.021251444
built-ruby	1.95159837
built-ruby	2.050155736
built-ruby	2.020469043

-----------------------------------------------------------
io_select2

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.268817064
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.268899095
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.358730819
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.321750407
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.204635163
built-ruby	3.347384167
built-ruby	3.259864779
built-ruby	3.302671526
built-ruby	3.167775641
built-ruby	3.228905385

-----------------------------------------------------------
io_select3

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.145442654
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.145994664
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.146822558
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.145668831
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.145997784
built-ruby	0.148458139
built-ruby	0.148310989
built-ruby	0.14875814
built-ruby	0.148683678
built-ruby	0.148133306

-----------------------------------------------------------
loop_for

for i in 1..30_000_000
  #
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.79656127
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.845368544
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.877121679
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.848727961
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.828819738
built-ruby	1.819038169
built-ruby	1.833455892
built-ruby	1.838806953
built-ruby	1.824281666
built-ruby	1.988214824

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.840437135
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.900624309
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.862098804
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.828637406
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.851913302
built-ruby	0.878908118
built-ruby	0.86467155
built-ruby	0.802884233
built-ruby	0.837899861
built-ruby	0.818225858

-----------------------------------------------------------
loop_times

30_000_000.times{|e|}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.693293532
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.639933084
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.609795681
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.61150662
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.651920259
built-ruby	1.669603306
built-ruby	1.669549478
built-ruby	1.689573281
built-ruby	1.687964544
built-ruby	1.695367949

-----------------------------------------------------------
loop_whileloop

i = 0
while i<30_000_000 # benchmark loop 1
  i += 1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.912980739
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.90293373
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.883051066
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.902885938
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.902771682
built-ruby	0.902966526
built-ruby	0.902893869
built-ruby	0.90288357
built-ruby	0.952745465
built-ruby	0.902956707

-----------------------------------------------------------
loop_whileloop2

i = 0
while i< 6_000_000 # benchmark loop 2
  i += 1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.186020273
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.185719222
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.185733945
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.185890602
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.185867937
built-ruby	0.185976126
built-ruby	0.185863991
built-ruby	0.195774881
built-ruby	0.186286457
built-ruby	0.186120495

-----------------------------------------------------------
so_ackermann

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)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.998498532
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.99646846
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.001302721
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.997179821
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.004339916
built-ruby	1.038670142
built-ruby	1.032183271
built-ruby	1.042432245
built-ruby	1.030370742
built-ruby	1.025507749

-----------------------------------------------------------
so_array

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.246222013
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.236795301
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.244046244
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.229664948
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.233599023
built-ruby	1.450627305
built-ruby	1.471119965
built-ruby	1.34908024
built-ruby	1.470841213
built-ruby	1.482310148

-----------------------------------------------------------
so_binary_trees

alias puts_orig puts
def puts str
  # disable puts
end

def item_check(tree)
 if tree[0] == nil
  tree[1]
 else
  tree[1] + item_check(tree[0]) - item_check(tree[2])
 end
end

def bottom_up_tree(item, depth)
 if depth > 0
  item_item = 2 * item
  depth -= 1
  [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
 else
  [nil, item, nil]
 end
end

max_depth = 16 # ARGV[0].to_i
min_depth = 4

max_depth = min_depth + 2 if min_depth + 2 > max_depth

stretch_depth = max_depth + 1
stretch_tree = bottom_up_tree(0, stretch_depth)

puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
stretch_tree = nil

long_lived_tree = bottom_up_tree(0, max_depth)

min_depth.step(max_depth + 1, 2) do |depth|
 iterations = 2**(max_depth - depth + min_depth)

 check = 0

 for i in 1..iterations
  temp_tree = bottom_up_tree(i, depth)
  check += item_check(temp_tree)

  temp_tree = bottom_up_tree(-i, depth)
  check += item_check(temp_tree)
 end

 puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
end

puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"

undef puts
alias puts puts_orig

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.588245817
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.66562622
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.559911313
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.551486153
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.602062264
built-ruby	13.429469336
built-ruby	13.574359023
built-ruby	13.879870553
built-ruby	13.462939126
built-ruby	13.510422083

-----------------------------------------------------------
so_concatenate

STUFF = "hello\n"
i = 0
while i<10
  i += 1
  hello = ''
  4_000_000.times do |e|
    hello << STUFF
  end
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	5.435282309
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	5.399846272
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	5.437168483
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	5.422394624
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	5.511567497
built-ruby	5.40623481
built-ruby	5.367025497
built-ruby	5.313366381
built-ruby	5.313879172
built-ruby	5.34907872

-----------------------------------------------------------
so_count_words

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.48525056
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.349812694
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.365675783
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.486048353
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.42114105
built-ruby	0.331323817
built-ruby	0.328271039
built-ruby	0.32119719
built-ruby	0.321740582
built-ruby	0.321354423

-----------------------------------------------------------
so_exception

$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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.47780881
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.486719072
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.487123229
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.492617376
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.481065822
built-ruby	0.58627721
built-ruby	0.584093425
built-ruby	0.586530791
built-ruby	0.598962354
built-ruby	0.604303874

-----------------------------------------------------------
so_fannkuch

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)}"

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.762067995
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.782776244
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.773046964
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.778307265
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.770239116
built-ruby	1.76449546
built-ruby	1.763080557
built-ruby	1.768760511
built-ruby	1.757747974
built-ruby	1.786945868

-----------------------------------------------------------
so_fasta

$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)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.873748722
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.863733839
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.868118723
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.848243174
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.84979631
built-ruby	2.799811237
built-ruby	2.788476143
built-ruby	2.797626251
built-ruby	2.835781876
built-ruby	2.80894853

-----------------------------------------------------------
so_k_nucleotide

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) }

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.252052012
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.268105079
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.248065705
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.248515541
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.265867947
built-ruby	1.889469044
built-ruby	1.899628319
built-ruby	1.900884047
built-ruby	1.897106311
built-ruby	1.909977068

-----------------------------------------------------------
so_lists

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<NUM
  i += 1
  result = test_lists()
end

result

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.862020392
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.871321634
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.87181159
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.885755441
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.880042928
built-ruby	0.86025227
built-ruby	0.869223686
built-ruby	0.877319204
built-ruby	0.845764777
built-ruby	0.84103591

-----------------------------------------------------------
so_mandelbrot

size = 600 # ARGV[0].to_i

puts "P4\n#{size} #{size}"

ITER = 49                           # Iterations - 1 for easy for..in looping
LIMIT_SQUARED = 4.0                 # Presquared limit

byte_acc = 0
bit_num = 0

count_size = size - 1               # Precomputed size for easy for..in looping

for y in 0..count_size
  for x in 0..count_size
    zr = 0.0
    zi = 0.0
    cr = (2.0*x/size)-1.5
    ci = (2.0*y/size)-1.0
    escape = false

    # To make use of the for..in code, we use a dummy variable,
    # like one would in C
    for dummy in 0..ITER
      tr = zr*zr - zi*zi + cr
      ti = 2*zr*zi + ci
      zr, zi = tr, ti

      if (zr*zr+zi*zi) > 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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.154330793
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.14831575
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.123538739
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.16572181
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.14255455
built-ruby	4.388808311
built-ruby	4.377818508
built-ruby	4.385771984
built-ruby	4.367810508
built-ruby	4.390630134

-----------------------------------------------------------
so_matrix

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.994578637
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.017545222
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.995951265
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.00018294
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.994120839
built-ruby	1.027740738
built-ruby	0.982193177
built-ruby	0.991256811
built-ruby	0.999998276
built-ruby	0.992446531

-----------------------------------------------------------
so_meteor_contest

def print *args
end

class Rotation
  # an array (by location) containing a bit mask for how the piece maps at the given location.
  # if the rotation is invalid at that location the mask will contain false
  attr_reader :start_masks

  # maps a direction to a relative location.  these differ depending on whether it is an even or
  # odd row being mapped from
  @@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 }
  @@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 }

  def initialize( directions )
    @even_offsets, @odd_offsets = normalize_offsets( get_values( directions ))

    @even_mask = mask_for_offsets( @even_offsets)
    @odd_mask = mask_for_offsets( @odd_offsets)

    @start_masks = Array.new(60)

    # create the rotational masks by placing the base mask at the location and seeing if
    # 1) it overlaps the boundaries and 2) it produces a prunable board.  if either of these
    # is true the piece cannot be placed
    0.upto(59) do | offset |
      mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset)
      if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then
        imask = compute_required( mask, offset)
        @start_masks[offset] = [ mask, imask, imask | mask ]
      else
        @start_masks[offset] = false
      end
    end
  end

  def compute_required( mask, offset )
    board = blank_board
    0.upto(offset) { | i | board |= 1 << i }
    board |= mask
    return 0 if (!prunable(board | mask, offset))
    board = flood_fill(board,58)
    count = 0
    imask = 0
    0.upto(59) do | i |
      if (board[i] == 0) then
        imask |= (1 << i)
        count += 1
      end
    end
    (count > 0 && count < 5) ? imask : 0
  end

  def flood_fill( board, location)
    return board if (board[location] == 1)
    board |= 1 << location
    row, col = location.divmod(6)
    board = flood_fill( board, location - 1) if (col > 0)
    board = flood_fill( board, location + 1) if (col < 4)
    if (row % 2 == 0) then
      board = flood_fill( board, location - 7) if (col > 0 && row > 0)
      board = flood_fill( board, location - 6) if (row > 0)
      board = flood_fill( board, location + 6) if (row < 9)
      board = flood_fill( board, location + 5) if (col > 0 && row < 9)
    else
      board = flood_fill( board, location - 5) if (col < 4 && row > 0)
      board = flood_fill( board, location - 6) if (row > 0)
      board = flood_fill( board, location + 6) if (row < 9)
      board = flood_fill( board, location + 7) if (col < 4 && row < 9)
    end
    board
  end

  # given a location, produces a list of relative locations covered by the piece at this rotation
  def offsets( location)
    if is_even( location) then
      @even_offsets.collect { | value | value + location }
    else
      @odd_offsets.collect { | value | value + location }
    end
  end

  # returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows)
  # this is hard to explain. imagine we have this partial board:
  #   0 0 0 0 0 x        [positions 0-5]
  #    0 0 1 1 0 x       [positions 6-11]
  #   0 0 1 0 0 x        [positions 12-17]
  #    0 1 0 0 0 x       [positions 18-23]
  #   0 1 0 0 0 x        [positions 24-29]
  #    0 0 0 0 0 x       [positions 30-35]
  #       ...
  # The top-left of the piece is at position 8, the
  # board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that
  # sorted order.  Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained
  # by subtracting 8 from everything.  Now imagine the piece shifted up and to the right so it's on an even row:
  #   0 0 0 1 1 x        [positions 0-5]
  #    0 0 1 0 0 x       [positions 6-11]
  #   0 0 1 0 0 x        [positions 12-17]
  #    0 1 0 0 0 x       [positions 18-23]
  #   0 0 0 0 0 x        [positions 24-29]
  #    0 0 0 0 0 x       [positions 30-35]
  #       ...
  # Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the
  # offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what
  # this function would return
  def normalize_offsets( values)
    min = values.min
    even_min = is_even(min)
    other_min = even_min ? min + 6 : min + 7
    other_values = values.collect do | value |
      if is_even(value) then
        value + 6 - other_min
      else
        value + 7 - other_min
      end
    end
    values.collect! { | value | value - min }

    if even_min then
      [values, other_values]
    else
      [other_values, values]
    end
  end

  # produce a bitmask representation of an array of offset locations
  def mask_for_offsets( offsets )
    mask = 0
    offsets.each { | value | mask = mask + ( 1 << value ) }
    mask
  end

  # finds a "safe" position that a position as described by a list of directions can be placed
  # without falling off any edge of the board.  the values returned a location to place the first piece
  # at so it will fit after making the described moves
  def start_adjust( directions )
    south = east = 0;
    directions.each do | direction |
      east += 1 if ( direction == :sw || direction == :nw || direction == :west )
      south += 1 if ( direction == :nw || direction == :ne )
    end
    south * 6 + east
  end

  # given a set of directions places the piece (as defined by a set of directions) on the board at
  # a location that will not take it off the edge
  def get_values ( directions )
    start = start_adjust(directions)
    values = [ start ]
    directions.each do | direction |
      if (start % 12 >= 6) then
        start += @@rotation_odd_adder[direction]
      else
        start += @@rotation_even_adder[direction]
      end
      values += [ start ]
    end

    # some moves take you back to an existing location, we'll strip duplicates
    values.uniq
  end
end

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

def blank_board
  0b111111100000100000100000100000100000100000100000100000100000100000
end

def full_board
  0b111111111111111111111111111111111111111111111111111111111111111111
end

def is_even( location)
  (location % 12) < 6
end

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

def prunable( board, location, slotting = false)
  collectors = []
  # loop across the rows
  (location / 6).to_i.upto(9) do | row_on |
    # obtain a set of regions representing the bits of the current row.
    regions = $regions[(board >> (row_on * 6)) & 0b11111]
    converter = $converter[row_on]

    # track the number of collectors at the start of the cycle so that
    # we don't compute against newly created collectors, only existing collectors
    initial_collector_count = collectors.length

    # loop against the regions.  For each region of the row
    # we will see if it connects to one or more existing collectors.
    # if it connects to 1 collector, the bits from the region are added to the
    # bits of the collector and the mask is placed in collector[2]
    # If the region overlaps more than one collector then all the collectors
    # it overlaps with are merged into the first one (the others are set to nil in the array)
    # if NO collectors are found then the region is copied as a new collector
    regions.each do | region |
      collector_found = nil
      region_mask = region[2]
      initial_collector_count.times do | collector_num |
        collector = collectors[collector_num]
        if (collector) then
          collector_mask = collector[0]
          if (collector_mask & region_mask != 0) then
            if (collector_found) then
              collector_found[0] |= collector_mask
              collector_found[1] += collector[1]
              collector_found[2] |= collector[2]
              collectors[collector_num] = nil
            else
              collector_found = collector
              collector[1] += region[1]
              collector[2] |= region_mask
            end
          end
        end
      end
      if (collector_found == nil) then
        collectors.push(Array.new(region))
      end
    end

    # check the existing collectors, if any collector overlapped no bits in the region its [2] value will
    # be zero.  The size of any such reaason is tested if it is not a multiple of five true is returned since
    # the board is prunable.  if it is a multiple of five it is removed.
    # Collector that are still active have a new adjacent value [0] set based n the matched bits
    # and have [2] cleared out for the next cycle.
    collectors.length.times do | collector_num |
      collector = collectors[collector_num]
      if (collector) then
        if (collector[2] == 0) then
          return true if (collector[1] % 5 != 0)
          collectors[collector_num] = nil
        else
          # if a collector matches all bits in the row then we can return unprunable early for the
          # following reasons:
          #    1) there can be no more unavailable bits bince we fill from the top left downward
          #    2) all previous regions have been closed or joined so only this region can fail
          #    3) this region must be good since there can never be only 1 region that is nuot
          #       a multiple of five
          # this rule only applies when filling normally, so we ignore the rule if we are "slotting"
          # in pieces to see what configurations work for them (the only other time this algorithm is used).
          return false if (collector[2] == 0b11111 && !slotting)
          collector[0] = converter[collector[2]]
          collector[2] = 0
        end
      end
    end

    # get rid of all the empty converters for the next round
    collectors.compact!
  end
  return false if (collectors.length <= 1) # 1 collector or less and the region is fine
  collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size
end

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

def find_all
  find_top( 1)
  find_top( 0)
  print_results
end

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

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

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

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

def add_board
  board_string = "99999999999999999999999999999999999999999999999999"
  @all_pieces.each {  | piece | piece.fill_string( board_string ) }
  save( board_string)
  save( board_string.reverse)
end

def save( board_string)
  if (@all_boards[board_string] == nil) then
    @min_board = board_string if (board_string < @min_board)
    @max_board = board_string if (board_string > @max_board)
    @all_boards.store(board_string,true)
    @boards_found += 1

    # the exit motif is a time saver.  Ideally the function should return, but those tests
    # take noticeable time (performance).
    if (@boards_found == @stop_count) then
      print_results
      exit(0)
    end
  end
end

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!!!

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.664526827
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.629831373
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.636308006
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.641459999
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.783680726
built-ruby	4.979619108
built-ruby	4.969523095
built-ruby	4.952307092
built-ruby	4.957374727
built-ruby	4.968125328

-----------------------------------------------------------
so_nbody

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)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.526172743
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.520346949
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.448498642
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.470640233
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.454321194
built-ruby	2.482318825
built-ruby	2.523244889
built-ruby	2.445610159
built-ruby	2.529953505
built-ruby	2.528239841

-----------------------------------------------------------
so_nested_loop

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.59474744
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.570329156
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.57085355
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.578531474
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.564589746
built-ruby	1.605287564
built-ruby	1.589290804
built-ruby	1.585082421
built-ruby	1.562563714
built-ruby	1.573668413

-----------------------------------------------------------
so_nsieve

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.617050285
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.608675879
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.613185684
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.664812442
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.669238533
built-ruby	3.762736003
built-ruby	3.779593146
built-ruby	3.6738903
built-ruby	3.727393469
built-ruby	3.736771018

-----------------------------------------------------------
so_nsieve_bits

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.552221642
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.614645346
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.648231322
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.534805495
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.638922921
built-ruby	4.121223921
built-ruby	4.126332748
built-ruby	4.159458514
built-ruby	4.145726011
built-ruby	4.168707682

-----------------------------------------------------------
so_object

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.970191338
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.959663459
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.976337259
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.963304918
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.969912878
built-ruby	1.012455662
built-ruby	1.005321508
built-ruby	1.081213612
built-ruby	1.060109121
built-ruby	1.020435223

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.824448337
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.958124181
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.847779562
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.888561178
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.856214339
built-ruby	3.670269195
built-ruby	3.656110404
built-ruby	3.664078121
built-ruby	3.657556941
built-ruby	3.579096753

-----------------------------------------------------------
so_pidigits

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.682464348
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.674477818
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.683373336
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.700944855
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.672326232
built-ruby	1.57947196
built-ruby	1.587416773
built-ruby	1.579485635
built-ruby	1.581360774
built-ruby	1.583045403

-----------------------------------------------------------
so_random

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<N
  i +=1
  gen_random(100.0)
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.576405676
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.60080942
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.577676069
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.602155367
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.581267884
built-ruby	0.610416149
built-ruby	0.624239881
built-ruby	0.60934668
built-ruby	0.612000866
built-ruby	0.583644923

-----------------------------------------------------------
so_reverse_complement

seq=Array.new

def revcomp(seq)
  seq.reverse!.tr!('wsatugcyrkmbdhvnATUGCYRKMBDHVN','WSTAACGRYMKVHDBNTAACGRYMKVHDBN')
  stringlen=seq.length
  0.step(stringlen-1,60) {|x| print seq.slice(x,60) , "\n"}
end

input = open(File.join(File.dirname($0), 'fasta.output.2500000'), 'rb')

while input.gets
  if $_ =~ />/
    if seq.length != 0
      revcomp(seq.join)
      seq=Array.new
    end
    puts $_
  else
    $_.sub(/\n/,'')
    seq.push $_
  end
end
revcomp(seq.join)

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.048253941
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.049140987
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.055608062
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.049360454
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.051429642
built-ruby	2.120182238
built-ruby	2.126457022
built-ruby	2.119072667
built-ruby	2.114138012
built-ruby	2.150296122

-----------------------------------------------------------
so_sieve

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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.886716628
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.892222211
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.889458533
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.887511991
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.878987102
built-ruby	0.953510075
built-ruby	0.91949093
built-ruby	0.914074849
built-ruby	0.949616134
built-ruby	0.902569523

-----------------------------------------------------------
so_spectralnorm

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"

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.226608243
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.279249259
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.297149644
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.249612003
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.230579658
built-ruby	3.323744301
built-ruby	3.356210032
built-ruby	3.180850048
built-ruby	3.321428894
built-ruby	3.370174183

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.472846834
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.582542447
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.562214698
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.554312993
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.534337109
built-ruby	2.426409001
built-ruby	2.431245179
built-ruby	2.432482863
built-ruby	2.426817675
built-ruby	2.423245356

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.047314043
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.036950381
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.056800231
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.070085229
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.043782427
built-ruby	2.954141217
built-ruby	3.007806091
built-ruby	2.946660472
built-ruby	2.972428018
built-ruby	2.985673746

-----------------------------------------------------------
vm1_block

def m
  yield
end

i = 0
while i<30_000_000 # while loop 1
  i += 1
  m{
  }
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.519844674
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.471742385
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.451730559
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.471683356
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.623523122
built-ruby	3.55290879
built-ruby	3.577567647
built-ruby	3.681165888
built-ruby	3.587905167
built-ruby	3.516341334

-----------------------------------------------------------
vm1_const

Const = 1

i = 0
while i<30_000_000 # while loop 1
  i += 1
  j = Const
  k = Const
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.542842525
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.542671159
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.552735627
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.552701111
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.533118757
built-ruby	1.552762143
built-ruby	1.552753724
built-ruby	1.552873112
built-ruby	1.532936018
built-ruby	1.55280671

-----------------------------------------------------------
vm1_ensure

i = 0
while i<30_000_000 # benchmark loop 1
  i += 1
  begin
    begin
    ensure
    end
  ensure
  end
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.984408287
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.984327412
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.984340009
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.974470499
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.984203652
built-ruby	0.984349467
built-ruby	0.974382867
built-ruby	0.974436801
built-ruby	0.97445648
built-ruby	0.974534277

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	8.437711767
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	8.611286401
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	8.505969695
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	8.548133978
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	8.712021356
built-ruby	8.323476646
built-ruby	8.611768777
built-ruby	8.554068587
built-ruby	8.57978778
built-ruby	8.235965626

-----------------------------------------------------------
vm1_gc_short_lived

i = 0
while i<30_000_000 # while loop 1
  a = '' # short-lived String
  b = ''
  c = ''
  d = ''
  e = ''
  f = ''
  i+=1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.238932607
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.552028341
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.333578397
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.618868735
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.293484346
built-ruby	16.24811247
built-ruby	16.179420157
built-ruby	16.162279052
built-ruby	16.105362595
built-ruby	16.110236024

-----------------------------------------------------------
vm1_gc_short_with_complex_long

def nested_hash h, n
  if n == 0
    ''
  else
    10.times{
      h[Object.new] = nested_hash(h, n-1)
    }
  end
end

long_lived = Hash.new
nested_hash long_lived, 6

GC.start
GC.start

i = 0
while i<30_000_000 # while loop 1
  a = '' # short-lived String
  b = ''
  c = ''
  d = ''
  e = ''
  f = ''
  i+=1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	19.165200948
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.730275281
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.953902548
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.769057222
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	19.038481617
built-ruby	18.850087634
built-ruby	18.949709452
built-ruby	18.908416281
built-ruby	18.898600574
built-ruby	18.899077807

-----------------------------------------------------------
vm1_gc_short_with_long

long_lived = Array.new(1_000_000){|i| "#{i}"}
GC.start
GC.start
i = 0
while i<30_000_000 # while loop 1
  a = '' # short-lived String
  b = ''
  c = ''
  d = ''
  e = ''
  f = ''
  i+=1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.93228402
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.856742089
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.643894095
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.814901303
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	18.647526163
built-ruby	18.637429058
built-ruby	18.672382184
built-ruby	18.670742904
built-ruby	18.619313444
built-ruby	18.661930916

-----------------------------------------------------------
vm1_gc_short_with_symbol

50_000.times{|i| sym = "sym#{i}".to_sym}
GC.start
GC.start

i = 0
while i<30_000_000 # while loop 1
  a = '' # short-lived String
  b = ''
  c = ''
  d = ''
  e = ''
  f = ''
  i+=1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.673613937
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.357689676
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.472314347
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.493082791
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	16.455694527
built-ruby	16.868583375
built-ruby	16.288265646
built-ruby	16.469642709
built-ruby	16.219433593
built-ruby	16.63710296

-----------------------------------------------------------
vm1_gc_wb_ary

long_lived = []
GC.start
GC.start

i = 0
short_lived = ''
while i<30_000_000 # while loop 1
  long_lived[0] = short_lived # write barrier
  i+=1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.849685222
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.859529293
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.860293292
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.807953295
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.849460776
built-ruby	1.819609765
built-ruby	1.819618591
built-ruby	1.81965225
built-ruby	1.844588068
built-ruby	1.849851378

-----------------------------------------------------------
vm1_gc_wb_obj

class C
  attr_accessor :foo
end
long_lived = C.new
GC.start
GC.start

i = 0
short_lived = ''
while i<30_000_000 # while loop 1
  long_lived.foo = short_lived # write barrier
  i+=1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.217883811
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.95902954
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.9987635
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.970195475
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.978945327
built-ruby	1.90932482
built-ruby	1.879403282
built-ruby	2.018829204
built-ruby	1.889330905
built-ruby	1.869447572

-----------------------------------------------------------
vm1_ivar

@a = 1

i = 0
while i<30_000_000 # while loop 1
  i += 1
  j = @a
  k = @a
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.724523253
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.709759215
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.725937656
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.69254203
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.724815482
built-ruby	1.722303
built-ruby	1.742614818
built-ruby	1.701593297
built-ruby	1.699034286
built-ruby	1.689691667

-----------------------------------------------------------
vm1_ivar_set

i = 0
while i<30_000_000 # while loop 1
  i += 1
  @a = 1
  @b = 2
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.695562164
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.699792536
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.679626226
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.69411823
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.715099464
built-ruby	1.701036947
built-ruby	1.70609433
built-ruby	1.722760428
built-ruby	1.700395776
built-ruby	1.691069187

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.872660065
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.883480217
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.861364487
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.84953808
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.865279091
built-ruby	1.718529467
built-ruby	1.734451574
built-ruby	1.753531871
built-ruby	1.730637061
built-ruby	1.730244679

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.365253768
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.476039465
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.68025067
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.902224552
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.288585214
built-ruby	3.322744838
built-ruby	3.239774098
built-ruby	3.405900883
built-ruby	3.738963243
built-ruby	3.44919756

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.962939536
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.962978563
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.9615901
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.9619323
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.240321286
built-ruby	4.220591004
built-ruby	4.220169996
built-ruby	4.220475908
built-ruby	4.222455602
built-ruby	3.949910275

-----------------------------------------------------------
vm1_neq

i = 0
obj1 = Object.new
obj2 = Object.new

while i<30_000_000 # while loop 1
  i += 1
  obj1 != obj2
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.86607163
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.889734664
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.905219381
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.900360143
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.894025762
built-ruby	1.759320805
built-ruby	1.759364114
built-ruby	1.789136746
built-ruby	1.779202787
built-ruby	1.759393901

-----------------------------------------------------------
vm1_not

i = 0
obj = Object.new

while i<30_000_000 # while loop 1
  i += 1
  !obj
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.380868984
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.350902546
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.341142116
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.35124267
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.35111311
built-ruby	1.34117707
built-ruby	1.331221822
built-ruby	1.351085145
built-ruby	1.341193712
built-ruby	1.341165591

-----------------------------------------------------------
vm1_rescue

i = 0
while i<30_000_000 # while loop 1
  i += 1
  begin
  rescue
  end
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.052458011
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.062403564
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.092288226
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.062164681
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.062234241
built-ruby	1.082321256
built-ruby	1.062220906
built-ruby	1.062079433
built-ruby	1.062300215
built-ruby	1.063184291

-----------------------------------------------------------
vm1_simplereturn

def m
  return 1
end
i = 0
while i<30_000_000 # while loop 1
  i += 1
  m
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.128771928
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.079268835
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.058822643
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.067997849
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.078974831
built-ruby	2.21019765
built-ruby	2.038209808
built-ruby	2.077963555
built-ruby	2.187453461
built-ruby	2.068185004

-----------------------------------------------------------
vm1_swap

a = 1
b = 2
i = 0
while i<30_000_000 # while loop 1
  i += 1
  a, b = b, a
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.311360379
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.301284006
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.301211458
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.301241265
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.261348036
built-ruby	1.251533222
built-ruby	1.281483894
built-ruby	1.241671062
built-ruby	1.281297015
built-ruby	1.28129641

-----------------------------------------------------------
vm1_yield

def m
  i = 0
  while i<30_000_000 # while loop 1
    i += 1
    yield
  end
end

m{}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.139783042
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.1130048
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.156692129
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.147406692
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.117711884
built-ruby	2.197443106
built-ruby	2.097745607
built-ruby	2.147946398
built-ruby	2.120152222
built-ruby	2.157521769

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.178533961
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.172840777
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.178746864
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.184835794
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.176301077
built-ruby	1.154115215
built-ruby	1.183506867
built-ruby	1.151520475
built-ruby	1.192249007
built-ruby	1.163617298

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	13.820011731
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	13.847945882
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	13.812999362
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	13.948018703
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	13.727943256
built-ruby	13.920973415
built-ruby	13.761085013
built-ruby	13.716240764
built-ruby	13.729871284
built-ruby	13.867524935

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	9.438776272
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	9.554111133
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	9.358678028
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	9.315145574
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	9.342472568
built-ruby	9.349338338
built-ruby	9.40615307
built-ruby	9.39321734
built-ruby	9.356088821
built-ruby	9.351294578

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.352903995
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.349280719
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.356661822
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.360753396
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.351187097
built-ruby	0.353554521
built-ruby	0.353278234
built-ruby	0.353318116
built-ruby	0.351155101
built-ruby	0.353138909

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.060958872
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.337830009
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.051080513
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.087408412
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	4.031283462
built-ruby	4.110717715
built-ruby	4.204938591
built-ruby	4.179246365
built-ruby	4.129826347
built-ruby	4.079056266

-----------------------------------------------------------
vm2_dstr

i = 0
x = y = 'z'
while i<6_000_000 # benchmark loop 2
  i += 1
  str = "foo#{x}bar#{y}baz"
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.510279632
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.342986909
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.41198014
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.362725462
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.427928173
built-ruby	2.371280482
built-ruby	2.3542066
built-ruby	2.374382992
built-ruby	2.376171619
built-ruby	2.411332527

-----------------------------------------------------------
vm2_eval

i = 0
while i<6_000_000 # benchmark loop 2
  i += 1
  eval("1")
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	24.385463209
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	24.70521687
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	25.008681884
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	25.486891393
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	25.044952034
built-ruby	24.476514167
built-ruby	24.268241021
built-ruby	24.519875814
built-ruby	24.058333665
built-ruby	24.045700088

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.016269944
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.984354874
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.024170053
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.998706459
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.003668717
built-ruby	1.995570464
built-ruby	1.993191271
built-ruby	2.025669329
built-ruby	2.00719773
built-ruby	2.081722365

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.063461759
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.048918593
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.056863628
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.08072429
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.130826177
built-ruby	3.806202068
built-ruby	3.536476829
built-ruby	3.667081172
built-ruby	3.537488244
built-ruby	3.606732995

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.165721757
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.283090696
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.231433517
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.167285906
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.161279087
built-ruby	2.263528369
built-ruby	2.219734408
built-ruby	2.182077478
built-ruby	2.190650827
built-ruby	2.232962204

-----------------------------------------------------------
vm2_mutex

require 'thread'

m = Mutex.new

i = 0
while i<6_000_000 # benchmark loop 2
  i += 1
  m.synchronize{}
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.179288771
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.141426599
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.151466002
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.166576645
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.169260215
built-ruby	1.134490821
built-ruby	1.127517043
built-ruby	1.154329455
built-ruby	1.121006523
built-ruby	1.148736541

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.330651059
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.346830834
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.314137158
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.337798532
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	3.3175212
built-ruby	3.951877884
built-ruby	3.845357579
built-ruby	3.903725811
built-ruby	4.026309566
built-ruby	3.863986998

-----------------------------------------------------------
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
  i += 1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.532704266
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.531693447
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.529857161
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.536826948
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.52901894
built-ruby	0.542722831
built-ruby	0.525429639
built-ruby	0.519810197
built-ruby	0.521183702
built-ruby	0.519911669

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.862038644
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.888017969
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.888656024
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.867815111
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.880962577
built-ruby	0.823410953
built-ruby	0.816930743
built-ruby	0.83020158
built-ruby	0.818906285
built-ruby	0.841126757

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.887921991
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.528144089
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.682430493
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.625388039
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	10.806859396
built-ruby	13.038204248
built-ruby	13.307852643
built-ruby	13.035781639
built-ruby	13.10801953
built-ruby	13.074143045

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	15.283643501
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	15.228040125
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	15.314340953
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	15.100060124
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	15.435972042
built-ruby	17.114223805
built-ruby	16.875283278
built-ruby	17.365957141
built-ruby	16.9675479
built-ruby	17.505366865

-----------------------------------------------------------
vm2_regexp

i = 0
str = 'xxxhogexxx'
while i<6_000_000 # benchmark loop 2
  /hoge/ =~ str
  i += 1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.716182416
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.718333887
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.7050151
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.718421819
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.699299604
built-ruby	1.687242266
built-ruby	1.696638079
built-ruby	1.661412707
built-ruby	1.713515572
built-ruby	1.727802831

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.642463908
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.641647259
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.642136287
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.640241588
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.640623935
built-ruby	0.691027166
built-ruby	0.692401885
built-ruby	0.725229923
built-ruby	0.717299119
built-ruby	0.714072912

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.911808276
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.949991904
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.905984972
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.060316634
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.903708737
built-ruby	0.9141817
built-ruby	0.937196139
built-ruby	0.922243078
built-ruby	0.924354183
built-ruby	0.951313862

-----------------------------------------------------------
vm2_unif1

i = 0
def m a, b
end

while i<6_000_000 # benchmark loop 2
  i += 1
  m 100, 200
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.455867788
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.474610635
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.475732909
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.478089404
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.474755714
built-ruby	0.513420101
built-ruby	0.508055333
built-ruby	0.490495103
built-ruby	0.511008538
built-ruby	0.523000318

-----------------------------------------------------------
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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.023950755
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.982844206
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.00335906
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.003923436
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.98535704
built-ruby	1.00176112
built-ruby	1.003802358
built-ruby	1.006477816
built-ruby	1.028025766
built-ruby	1.018284985

-----------------------------------------------------------
vm3_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

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.204742183
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.200042989
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.201306261
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.214273036
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.206221482
built-ruby	0.188882841
built-ruby	0.184540942
built-ruby	0.189131147
built-ruby	0.187569626
built-ruby	0.189574668

-----------------------------------------------------------
vm3_clearmethodcache

i = 0
while i<200_000
  i += 1

  Class.new{
    def m; end
  }
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.570759864
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.638716865
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.649349212
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.636861997
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.619823152
built-ruby	0.578165687
built-ruby	0.653758612
built-ruby	0.621234845
built-ruby	0.61168799
built-ruby	0.594815394

-----------------------------------------------------------
vm3_gc

5000.times do
  100.times do
    {"xxxx"=>"yyyy"}
  end
  GC.start
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.662186805
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.678460591
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.662376588
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.66444135
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.639761567
built-ruby	1.647167774
built-ruby	1.670009914
built-ruby	1.633922221
built-ruby	1.645656402
built-ruby	1.634264223

-----------------------------------------------------------
vm_thread_alive_check1

5_000.times{
  t = Thread.new{}
  while t.alive?
    Thread.pass
  end
}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.127843624
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.130238569
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.142373348
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.127529432
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.124812928
built-ruby	0.128848841
built-ruby	0.169635094
built-ruby	0.129089361
built-ruby	0.133343715
built-ruby	0.126079399

-----------------------------------------------------------
vm_thread_create_join

i = 0
while i<100_000 # benchmark loop 3
  i += 1
  Thread.new{
  }.join
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.268229698
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.318634703
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.269651354
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.290722589
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.322946293
built-ruby	2.352855543
built-ruby	2.276850313
built-ruby	2.254862089
built-ruby	2.306960944
built-ruby	2.306854021

-----------------------------------------------------------
vm_thread_mutex1

require 'thread'
m = Mutex.new
r = 0
max = 2000
lmax = max * max
(1..1).map{
  Thread.new{
    i = 0
    while i<lmax
      i += 1
      m.synchronize{
        r += 1
      }
    end
  }
}.each{|e|
  e.join
}
raise r.to_s if r != max * max

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.864795646
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.867611237
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.863844768
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.862765398
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.863064912
built-ruby	0.882349759
built-ruby	0.895910957
built-ruby	0.886402147
built-ruby	0.88120339
built-ruby	0.884175859

-----------------------------------------------------------
vm_thread_mutex2

require 'thread'
m = Mutex.new
r = 0
max = 2000
lmax = (max * max)/2
(1..2).map{
  Thread.new{
    i = 0
    while i<lmax
      i += 1
      m.synchronize{
        r += 1
      }
    end
  }
}.each{|e|
  e.join
}
raise r.to_s if r != max * max

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.158309694
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.649379307
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.527173954
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	2.245150197
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	1.196752369
built-ruby	2.938418252
built-ruby	1.539196058
built-ruby	2.204856416
built-ruby	2.282647253
built-ruby	1.96847491

-----------------------------------------------------------
vm_thread_mutex3

require 'thread'
m = Mutex.new
r = 0
max = 2000
(1..max).map{
  Thread.new{
    i = 0
    while i<max
      i += 1
      m.synchronize{
        r += 1
      }
    end
  }
}.each{|e|
  e.join
}
raise r.to_s if r != max * max

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	37.504255606
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	37.935336454
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	37.218349936
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	37.715427605
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	32.940120956
built-ruby	36.858487072
built-ruby	36.917814071
built-ruby	37.235446698
built-ruby	37.042815912
built-ruby	32.838111457

-----------------------------------------------------------
vm_thread_pass

tmax = (ARGV.shift || 2).to_i
lmax = 200_000 / tmax

(1..tmax).map{
  Thread.new{
    lmax.times{
      Thread.pass
    }
  }
}.each{|t| t.join}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.937644079
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.896472311
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.921838017
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.931619637
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.913110504
built-ruby	0.893858776
built-ruby	0.978469925
built-ruby	0.917294131
built-ruby	0.864654724
built-ruby	0.921055434

-----------------------------------------------------------
vm_thread_pass_flood

1000.times{
  Thread.new{loop{Thread.pass}}
}

i = 0
while i<10000
  i += 1
end

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.096857027
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.096828408
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.097164051
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.09685827
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.097811524
built-ruby	0.095764197
built-ruby	0.097875102
built-ruby	0.09771245
built-ruby	0.096748181
built-ruby	0.097135557

-----------------------------------------------------------
vm_thread_pipe

lmax = 100_000
r, w = IO.pipe
[Thread.new{
  lmax.times{
    w.write('a')
  }
  p "w:exit"
}, Thread.new{
  lmax.times{
    r.read(1)
  }
  p "r:exit"
}].each{|t| t.join}

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.92354242
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.797927528
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.827020854
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.847922435
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.83829522
built-ruby	0.831319597
built-ruby	0.858402645
built-ruby	0.867490898
built-ruby	0.833695067
built-ruby	0.801210948

-----------------------------------------------------------
vm_thread_queue

require 'thread'

n = 1_000_000
q = Queue.new
consumer = Thread.new{
  while q.pop
    # consuming
  end
}

producer = Thread.new{
  n.times{
    q.push true
  }
  q.push nil
}

consumer.join

ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.173637491
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.174469993
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.171893156
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.173939655
ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	0.173203597
built-ruby	0.168403201
built-ruby	0.17406139
built-ruby	0.173260273
built-ruby	0.173878636
built-ruby	0.169219555

-----------------------------------------------------------
raw data:

[["app_answer",
  [[0.069115958, 0.06926997, 0.06921102, 0.069450381, 0.06918108],
   [0.07046214, 0.071342715, 0.071297448, 0.071299547, 0.071684754]]],
 ["app_aobench",
  [[82.528179264, 86.038767054, 83.955373562, 83.931281878, 83.744656236],
   [86.047444711, 86.970111775, 86.703384838, 85.086941462, 87.40537543]]],
 ["app_erb",
  [[1.46321774, 1.471494815, 1.474278595, 1.485722449, 1.467138188],
   [1.533831156, 1.523069245, 1.520039886, 1.517973937, 1.516723692]]],
 ["app_factorial",
  [[1.368356244, 1.371527404, 1.355026275, 1.348838127, 1.354984164],
   [1.340291532, 1.339430568, 1.345734561, 1.338615726, 1.345918855]]],
 ["app_fib",
  [[0.837208189, 0.833599869, 0.833381765, 0.832548653, 0.83341986],
   [0.836904428, 0.841274597, 0.840583958, 0.841151469, 0.967884473]]],
 ["app_mandelbrot",
  [[1.800706663, 1.749651764, 1.747574821, 1.782274642, 1.745952519],
   [2.283323719, 2.279653605, 2.273155713, 2.327998505, 2.250825736]]],
 ["app_pentomino",
  [[24.296385154, 24.38995728, 24.177945801, 24.380250106, 24.188389453],
   [24.370961852, 24.416938988, 24.440741607, 24.532772735, 24.538908662]]],
 ["app_raise",
  [[0.492213775, 0.492685653, 0.493051224, 0.488393417, 0.485406938],
   [0.615535319, 0.609878188, 0.602776171, 0.601432916, 0.600821616]]],
 ["app_strconcat",
  [[1.579476486, 1.598758991, 1.603527045, 1.627146082, 1.603781493],
   [1.744377507, 1.773091946, 1.800217493, 1.759609869, 1.749171655]]],
 ["app_tak",
  [[1.106726826, 1.177076003, 1.110256736, 1.110182835, 1.107473709],
   [1.235649576, 1.233945608, 1.240364787, 1.156158583, 1.21089341]]],
 ["app_tarai",
  [[0.917232531, 0.903223315, 0.893586256, 0.894859441, 0.895607827],
   [0.966387685, 0.980843355, 0.934894547, 0.907297411, 0.963007847]]],
 ["app_uri",
  [[1.099568786, 1.082000754, 1.081822547, 1.076911935, 1.087471019],
   [1.156177298, 1.160693997, 1.155310872, 1.154901146, 1.139590661]]],
 ["hash_flatten",
  [[0.902394802, 0.884952246, 0.887560944, 0.881342081, 0.879146229],
   [0.873058744, 0.874640084, 0.877583221, 0.872320747, 0.876329697]]],
 ["hash_keys",
  [[0.397029458, 0.407694535, 0.400637665, 0.400234933, 0.402138458],
   [0.402534751, 0.410476245, 0.405091748, 0.396720909, 0.399763643]]],
 ["hash_shift",
  [[0.037129663, 0.036840547, 0.036222653, 0.036399887, 0.037119105],
   [0.038616534, 0.03931956, 0.038513296, 0.038836303, 0.038827658]]],
 ["hash_values",
  [[0.406103511, 0.404399534, 0.408950118, 0.408736098, 0.407261318],
   [0.402660006, 0.408974861, 0.40790732, 0.405073422, 0.401911494]]],
 ["io_file_create",
  [[1.352278127, 1.307616344, 1.328492224, 1.328006981, 1.339089271],
   [1.538196822, 1.513475723, 1.486812243, 1.530780153, 1.528907202]]],
 ["io_file_read",
  [[2.347668338, 2.256763758, 2.281661785, 2.240669561, 2.322793482],
   [2.248574806, 2.248717567, 2.259497669, 2.305376805, 2.245098167]]],
 ["io_file_write",
  [[1.217298688, 1.180208878, 1.15500956, 1.178688551, 1.190234321],
   [1.217829388, 1.241709339, 1.228997633, 1.183735168, 1.226485586]]],
 ["io_select",
  [[2.104997937, 2.121240421, 1.997004746, 2.002810271, 2.02273593],
   [1.955583178, 2.021251444, 1.95159837, 2.050155736, 2.020469043]]],
 ["io_select2",
  [[3.268817064, 3.268899095, 3.358730819, 3.321750407, 3.204635163],
   [3.347384167, 3.259864779, 3.302671526, 3.167775641, 3.228905385]]],
 ["io_select3",
  [[0.145442654, 0.145994664, 0.146822558, 0.145668831, 0.145997784],
   [0.148458139, 0.148310989, 0.14875814, 0.148683678, 0.148133306]]],
 ["loop_for",
  [[1.79656127, 1.845368544, 1.877121679, 1.848727961, 1.828819738],
   [1.819038169, 1.833455892, 1.838806953, 1.824281666, 1.988214824]]],
 ["loop_generator",
  [[0.840437135, 0.900624309, 0.862098804, 0.828637406, 0.851913302],
   [0.878908118, 0.86467155, 0.802884233, 0.837899861, 0.818225858]]],
 ["loop_times",
  [[1.693293532, 1.639933084, 1.609795681, 1.61150662, 1.651920259],
   [1.669603306, 1.669549478, 1.689573281, 1.687964544, 1.695367949]]],
 ["loop_whileloop",
  [[0.912980739, 0.90293373, 0.883051066, 0.902885938, 0.902771682],
   [0.902966526, 0.902893869, 0.90288357, 0.952745465, 0.902956707]]],
 ["loop_whileloop2",
  [[0.186020273, 0.185719222, 0.185733945, 0.185890602, 0.185867937],
   [0.185976126, 0.185863991, 0.195774881, 0.186286457, 0.186120495]]],
 ["so_ackermann",
  [[0.998498532, 0.99646846, 1.001302721, 0.997179821, 1.004339916],
   [1.038670142, 1.032183271, 1.042432245, 1.030370742, 1.025507749]]],
 ["so_array",
  [[1.246222013, 1.236795301, 1.244046244, 1.229664948, 1.233599023],
   [1.450627305, 1.471119965, 1.34908024, 1.470841213, 1.482310148]]],
 ["so_binary_trees",
  [[10.588245817, 10.66562622, 10.559911313, 10.551486153, 10.602062264],
   [13.429469336, 13.574359023, 13.879870553, 13.462939126, 13.510422083]]],
 ["so_concatenate",
  [[5.435282309, 5.399846272, 5.437168483, 5.422394624, 5.511567497],
   [5.40623481, 5.367025497, 5.313366381, 5.313879172, 5.34907872]]],
 ["so_count_words",
  [[0.48525056, 0.349812694, 0.365675783, 0.486048353, 0.42114105],
   [0.331323817, 0.328271039, 0.32119719, 0.321740582, 0.321354423]]],
 ["so_exception",
  [[0.47780881, 0.486719072, 0.487123229, 0.492617376, 0.481065822],
   [0.58627721, 0.584093425, 0.586530791, 0.598962354, 0.604303874]]],
 ["so_fannkuch",
  [[1.762067995, 1.782776244, 1.773046964, 1.778307265, 1.770239116],
   [1.76449546, 1.763080557, 1.768760511, 1.757747974, 1.786945868]]],
 ["so_fasta",
  [[2.873748722, 2.863733839, 2.868118723, 2.848243174, 2.84979631],
   [2.799811237, 2.788476143, 2.797626251, 2.835781876, 2.80894853]]],
 ["so_k_nucleotide",
  [[2.252052012, 2.268105079, 2.248065705, 2.248515541, 2.265867947],
   [1.889469044, 1.899628319, 1.900884047, 1.897106311, 1.909977068]]],
 ["so_lists",
  [[0.862020392, 0.871321634, 0.87181159, 0.885755441, 0.880042928],
   [0.86025227, 0.869223686, 0.877319204, 0.845764777, 0.84103591]]],
 ["so_mandelbrot",
  [[4.154330793, 4.14831575, 4.123538739, 4.16572181, 4.14255455],
   [4.388808311, 4.377818508, 4.385771984, 4.367810508, 4.390630134]]],
 ["so_matrix",
  [[0.994578637, 1.017545222, 0.995951265, 1.00018294, 0.994120839],
   [1.027740738, 0.982193177, 0.991256811, 0.999998276, 0.992446531]]],
 ["so_meteor_contest",
  [[4.664526827, 4.629831373, 4.636308006, 4.641459999, 4.783680726],
   [4.979619108, 4.969523095, 4.952307092, 4.957374727, 4.968125328]]],
 ["so_nbody",
  [[2.526172743, 2.520346949, 2.448498642, 2.470640233, 2.454321194],
   [2.482318825, 2.523244889, 2.445610159, 2.529953505, 2.528239841]]],
 ["so_nested_loop",
  [[1.59474744, 1.570329156, 1.57085355, 1.578531474, 1.564589746],
   [1.605287564, 1.589290804, 1.585082421, 1.562563714, 1.573668413]]],
 ["so_nsieve",
  [[3.617050285, 3.608675879, 3.613185684, 3.664812442, 3.669238533],
   [3.762736003, 3.779593146, 3.6738903, 3.727393469, 3.736771018]]],
 ["so_nsieve_bits",
  [[3.552221642, 3.614645346, 3.648231322, 3.534805495, 3.638922921],
   [4.121223921, 4.126332748, 4.159458514, 4.145726011, 4.168707682]]],
 ["so_object",
  [[0.970191338, 0.959663459, 0.976337259, 0.963304918, 0.969912878],
   [1.012455662, 1.005321508, 1.081213612, 1.060109121, 1.020435223]]],
 ["so_partial_sums",
  [[3.824448337, 3.958124181, 3.847779562, 3.888561178, 3.856214339],
   [3.670269195, 3.656110404, 3.664078121, 3.657556941, 3.579096753]]],
 ["so_pidigits",
  [[1.682464348, 1.674477818, 1.683373336, 1.700944855, 1.672326232],
   [1.57947196, 1.587416773, 1.579485635, 1.581360774, 1.583045403]]],
 ["so_random",
  [[0.576405676, 0.60080942, 0.577676069, 0.602155367, 0.581267884],
   [0.610416149, 0.624239881, 0.60934668, 0.612000866, 0.583644923]]],
 ["so_reverse_complement",
  [[2.048253941, 2.049140987, 2.055608062, 2.049360454, 2.051429642],
   [2.120182238, 2.126457022, 2.119072667, 2.114138012, 2.150296122]]],
 ["so_sieve",
  [[0.886716628, 0.892222211, 0.889458533, 0.887511991, 0.878987102],
   [0.953510075, 0.91949093, 0.914074849, 0.949616134, 0.902569523]]],
 ["so_spectralnorm",
  [[3.226608243, 3.279249259, 3.297149644, 3.249612003, 3.230579658],
   [3.323744301, 3.356210032, 3.180850048, 3.321428894, 3.370174183]]],
 ["vm1_attr_ivar",
  [[2.472846834, 2.582542447, 2.562214698, 2.554312993, 2.534337109],
   [2.426409001, 2.431245179, 2.432482863, 2.426817675, 2.423245356]]],
 ["vm1_attr_ivar_set",
  [[3.047314043, 3.036950381, 3.056800231, 3.070085229, 3.043782427],
   [2.954141217, 3.007806091, 2.946660472, 2.972428018, 2.985673746]]],
 ["vm1_block",
  [[3.519844674, 3.471742385, 3.451730559, 3.471683356, 3.623523122],
   [3.55290879, 3.577567647, 3.681165888, 3.587905167, 3.516341334]]],
 ["vm1_const",
  [[1.542842525, 1.542671159, 1.552735627, 1.552701111, 1.533118757],
   [1.552762143, 1.552753724, 1.552873112, 1.532936018, 1.55280671]]],
 ["vm1_ensure",
  [[0.984408287, 0.984327412, 0.984340009, 0.974470499, 0.984203652],
   [0.984349467, 0.974382867, 0.974436801, 0.97445648, 0.974534277]]],
 ["vm1_float_simple",
  [[8.437711767, 8.611286401, 8.505969695, 8.548133978, 8.712021356],
   [8.323476646, 8.611768777, 8.554068587, 8.57978778, 8.235965626]]],
 ["vm1_gc_short_lived",
  [[16.238932607, 16.552028341, 16.333578397, 16.618868735, 16.293484346],
   [16.24811247, 16.179420157, 16.162279052, 16.105362595, 16.110236024]]],
 ["vm1_gc_short_with_complex_long",
  [[19.165200948, 18.730275281, 18.953902548, 18.769057222, 19.038481617],
   [18.850087634, 18.949709452, 18.908416281, 18.898600574, 18.899077807]]],
 ["vm1_gc_short_with_long",
  [[18.93228402, 18.856742089, 18.643894095, 18.814901303, 18.647526163],
   [18.637429058, 18.672382184, 18.670742904, 18.619313444, 18.661930916]]],
 ["vm1_gc_short_with_symbol",
  [[16.673613937, 16.357689676, 16.472314347, 16.493082791, 16.455694527],
   [16.868583375, 16.288265646, 16.469642709, 16.219433593, 16.63710296]]],
 ["vm1_gc_wb_ary",
  [[1.849685222, 1.859529293, 1.860293292, 1.807953295, 1.849460776],
   [1.819609765, 1.819618591, 1.81965225, 1.844588068, 1.849851378]]],
 ["vm1_gc_wb_obj",
  [[2.217883811, 1.95902954, 1.9987635, 1.970195475, 1.978945327],
   [1.90932482, 1.879403282, 2.018829204, 1.889330905, 1.869447572]]],
 ["vm1_ivar",
  [[1.724523253, 1.709759215, 1.725937656, 1.69254203, 1.724815482],
   [1.722303, 1.742614818, 1.701593297, 1.699034286, 1.689691667]]],
 ["vm1_ivar_set",
  [[1.695562164, 1.699792536, 1.679626226, 1.69411823, 1.715099464],
   [1.701036947, 1.70609433, 1.722760428, 1.700395776, 1.691069187]]],
 ["vm1_length",
  [[1.872660065, 1.883480217, 1.861364487, 1.84953808, 1.865279091],
   [1.718529467, 1.734451574, 1.753531871, 1.730637061, 1.730244679]]],
 ["vm1_lvar_init",
  [[3.365253768, 3.476039465, 3.68025067, 3.902224552, 4.288585214],
   [3.322744838, 3.239774098, 3.405900883, 3.738963243, 3.44919756]]],
 ["vm1_lvar_set",
  [[3.962939536, 3.962978563, 3.9615901, 3.9619323, 4.240321286],
   [4.220591004, 4.220169996, 4.220475908, 4.222455602, 3.949910275]]],
 ["vm1_neq",
  [[1.86607163, 1.889734664, 1.905219381, 1.900360143, 1.894025762],
   [1.759320805, 1.759364114, 1.789136746, 1.779202787, 1.759393901]]],
 ["vm1_not",
  [[1.380868984, 1.350902546, 1.341142116, 1.35124267, 1.35111311],
   [1.34117707, 1.331221822, 1.351085145, 1.341193712, 1.341165591]]],
 ["vm1_rescue",
  [[1.052458011, 1.062403564, 1.092288226, 1.062164681, 1.062234241],
   [1.082321256, 1.062220906, 1.062079433, 1.062300215, 1.063184291]]],
 ["vm1_simplereturn",
  [[2.128771928, 2.079268835, 2.058822643, 2.067997849, 2.078974831],
   [2.21019765, 2.038209808, 2.077963555, 2.187453461, 2.068185004]]],
 ["vm1_swap",
  [[1.311360379, 1.301284006, 1.301211458, 1.301241265, 1.261348036],
   [1.251533222, 1.281483894, 1.241671062, 1.281297015, 1.28129641]]],
 ["vm1_yield",
  [[2.139783042, 2.1130048, 2.156692129, 2.147406692, 2.117711884],
   [2.197443106, 2.097745607, 2.147946398, 2.120152222, 2.157521769]]],
 ["vm2_array",
  [[1.178533961, 1.172840777, 1.178746864, 1.184835794, 1.176301077],
   [1.154115215, 1.183506867, 1.151520475, 1.192249007, 1.163617298]]],
 ["vm2_bigarray",
  [[13.820011731, 13.847945882, 13.812999362, 13.948018703, 13.727943256],
   [13.920973415, 13.761085013, 13.716240764, 13.729871284, 13.867524935]]],
 ["vm2_bighash",
  [[9.438776272, 9.554111133, 9.358678028, 9.315145574, 9.342472568],
   [9.349338338, 9.40615307, 9.39321734, 9.356088821, 9.351294578]]],
 ["vm2_case",
  [[0.352903995, 0.349280719, 0.356661822, 0.360753396, 0.351187097],
   [0.353554521, 0.353278234, 0.353318116, 0.351155101, 0.353138909]]],
 ["vm2_defined_method",
  [[4.060958872, 4.337830009, 4.051080513, 4.087408412, 4.031283462],
   [4.110717715, 4.204938591, 4.179246365, 4.129826347, 4.079056266]]],
 ["vm2_dstr",
  [[2.510279632, 2.342986909, 2.41198014, 2.362725462, 2.427928173],
   [2.371280482, 2.3542066, 2.374382992, 2.376171619, 2.411332527]]],
 ["vm2_eval",
  [[24.385463209, 24.70521687, 25.008681884, 25.486891393, 25.044952034],
   [24.476514167, 24.268241021, 24.519875814, 24.058333665, 24.045700088]]],
 ["vm2_method",
  [[2.016269944, 1.984354874, 2.024170053, 1.998706459, 2.003668717],
   [1.995570464, 1.993191271, 2.025669329, 2.00719773, 2.081722365]]],
 ["vm2_method_missing",
  [[3.063461759, 3.048918593, 3.056863628, 3.08072429, 3.130826177],
   [3.806202068, 3.536476829, 3.667081172, 3.537488244, 3.606732995]]],
 ["vm2_method_with_block",
  [[2.165721757, 2.283090696, 2.231433517, 2.167285906, 2.161279087],
   [2.263528369, 2.219734408, 2.182077478, 2.190650827, 2.232962204]]],
 ["vm2_mutex",
  [[1.179288771, 1.141426599, 1.151466002, 1.166576645, 1.169260215],
   [1.134490821, 1.127517043, 1.154329455, 1.121006523, 1.148736541]]],
 ["vm2_poly_method",
  [[3.330651059, 3.346830834, 3.314137158, 3.337798532, 3.3175212],
   [3.951877884, 3.845357579, 3.903725811, 4.026309566, 3.863986998]]],
 ["vm2_poly_method_ov",
  [[0.532704266, 0.531693447, 0.529857161, 0.536826948, 0.52901894],
   [0.542722831, 0.525429639, 0.519810197, 0.521183702, 0.519911669]]],
 ["vm2_proc",
  [[0.862038644, 0.888017969, 0.888656024, 0.867815111, 0.880962577],
   [0.823410953, 0.816930743, 0.83020158, 0.818906285, 0.841126757]]],
 ["vm2_raise1",
  [[10.887921991, 10.528144089, 10.682430493, 10.625388039, 10.806859396],
   [13.038204248, 13.307852643, 13.035781639, 13.10801953, 13.074143045]]],
 ["vm2_raise2",
  [[15.283643501, 15.228040125, 15.314340953, 15.100060124, 15.435972042],
   [17.114223805, 16.875283278, 17.365957141, 16.9675479, 17.505366865]]],
 ["vm2_regexp",
  [[1.716182416, 1.718333887, 1.7050151, 1.718421819, 1.699299604],
   [1.687242266, 1.696638079, 1.661412707, 1.713515572, 1.727802831]]],
 ["vm2_send",
  [[0.642463908, 0.641647259, 0.642136287, 0.640241588, 0.640623935],
   [0.691027166, 0.692401885, 0.725229923, 0.717299119, 0.714072912]]],
 ["vm2_super",
  [[0.911808276, 0.949991904, 0.905984972, 1.060316634, 0.903708737],
   [0.9141817, 0.937196139, 0.922243078, 0.924354183, 0.951313862]]],
 ["vm2_unif1",
  [[0.455867788, 0.474610635, 0.475732909, 0.478089404, 0.474755714],
   [0.513420101, 0.508055333, 0.490495103, 0.511008538, 0.523000318]]],
 ["vm2_zsuper",
  [[1.023950755, 0.982844206, 1.00335906, 1.003923436, 0.98535704],
   [1.00176112, 1.003802358, 1.006477816, 1.028025766, 1.018284985]]],
 ["vm3_backtrace",
  [[0.204742183, 0.200042989, 0.201306261, 0.214273036, 0.206221482],
   [0.188882841, 0.184540942, 0.189131147, 0.187569626, 0.189574668]]],
 ["vm3_clearmethodcache",
  [[0.570759864, 0.638716865, 0.649349212, 0.636861997, 0.619823152],
   [0.578165687, 0.653758612, 0.621234845, 0.61168799, 0.594815394]]],
 ["vm3_gc",
  [[1.662186805, 1.678460591, 1.662376588, 1.66444135, 1.639761567],
   [1.647167774, 1.670009914, 1.633922221, 1.645656402, 1.634264223]]],
 ["vm_thread_alive_check1",
  [[0.127843624, 0.130238569, 0.142373348, 0.127529432, 0.124812928],
   [0.128848841, 0.169635094, 0.129089361, 0.133343715, 0.126079399]]],
 ["vm_thread_create_join",
  [[2.268229698, 2.318634703, 2.269651354, 2.290722589, 2.322946293],
   [2.352855543, 2.276850313, 2.254862089, 2.306960944, 2.306854021]]],
 ["vm_thread_mutex1",
  [[0.864795646, 0.867611237, 0.863844768, 0.862765398, 0.863064912],
   [0.882349759, 0.895910957, 0.886402147, 0.88120339, 0.884175859]]],
 ["vm_thread_mutex2",
  [[2.158309694, 1.649379307, 1.527173954, 2.245150197, 1.196752369],
   [2.938418252, 1.539196058, 2.204856416, 2.282647253, 1.96847491]]],
 ["vm_thread_mutex3",
  [[37.504255606, 37.935336454, 37.218349936, 37.715427605, 32.940120956],
   [36.858487072, 36.917814071, 37.235446698, 37.042815912, 32.838111457]]],
 ["vm_thread_pass",
  [[0.937644079, 0.896472311, 0.921838017, 0.931619637, 0.913110504],
   [0.893858776, 0.978469925, 0.917294131, 0.864654724, 0.921055434]]],
 ["vm_thread_pass_flood",
  [[0.096857027, 0.096828408, 0.097164051, 0.09685827, 0.097811524],
   [0.095764197, 0.097875102, 0.09771245, 0.096748181, 0.097135557]]],
 ["vm_thread_pipe",
  [[0.92354242, 0.797927528, 0.827020854, 0.847922435, 0.83829522],
   [0.831319597, 0.858402645, 0.867490898, 0.833695067, 0.801210948]]],
 ["vm_thread_queue",
  [[0.173637491, 0.174469993, 0.171893156, 0.173939655, 0.173203597],
   [0.168403201, 0.17406139, 0.173260273, 0.173878636, 0.169219555]]]]

Elapsed time: 4673.491688135 (sec)
-----------------------------------------------------------
benchmark results:
minimum results in each 5 measurements.
Execution time (sec)
name	ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]	built-ruby
app_answer	0.069	0.070
app_aobench	82.528	85.087
app_erb	1.463	1.517
app_factorial	1.349	1.339
app_fib	0.833	0.837
app_mandelbrot	1.746	2.251
app_pentomino	24.178	24.371
app_raise	0.485	0.601
app_strconcat	1.579	1.744
app_tak	1.107	1.156
app_tarai	0.894	0.907
app_uri	1.077	1.140
hash_flatten	0.879	0.872
hash_keys	0.397	0.397
hash_shift	0.036	0.039
hash_values	0.404	0.402
io_file_create	1.308	1.487
io_file_read	2.241	2.245
io_file_write	1.155	1.184
io_select	1.997	1.952
io_select2	3.205	3.168
io_select3	0.145	0.148
loop_for	1.797	1.819
loop_generator	0.829	0.803
loop_times	1.610	1.670
loop_whileloop	0.883	0.903
loop_whileloop2	0.186	0.186
so_ackermann	0.996	1.026
so_array	1.230	1.349
so_binary_trees	10.551	13.429
so_concatenate	5.400	5.313
so_count_words	0.350	0.321
so_exception	0.478	0.584
so_fannkuch	1.762	1.758
so_fasta	2.848	2.788
so_k_nucleotide	2.248	1.889
so_lists	0.862	0.841
so_mandelbrot	4.124	4.368
so_matrix	0.994	0.982
so_meteor_contest	4.630	4.952
so_nbody	2.448	2.446
so_nested_loop	1.565	1.563
so_nsieve	3.609	3.674
so_nsieve_bits	3.535	4.121
so_object	0.960	1.005
so_partial_sums	3.824	3.579
so_pidigits	1.672	1.579
so_random	0.576	0.584
so_reverse_complement	2.048	2.114
so_sieve	0.879	0.903
so_spectralnorm	3.227	3.181
vm1_attr_ivar*	1.590	1.520
vm1_attr_ivar_set*	2.154	2.044
vm1_block*	2.569	2.613
vm1_const*	0.650	0.630
vm1_ensure*	0.091	0.071
vm1_float_simple*	7.555	7.333
vm1_gc_short_lived*	15.356	15.202
vm1_gc_short_with_complex_long*	17.847	17.947
vm1_gc_short_with_long*	17.761	17.716
vm1_gc_short_with_symbol*	15.475	15.317
vm1_gc_wb_ary*	0.925	0.917
vm1_gc_wb_obj*	1.076	0.967
vm1_ivar*	0.809	0.787
vm1_ivar_set*	0.797	0.788
vm1_length*	0.966	0.816
vm1_lvar_init*	2.482	2.337
vm1_lvar_set*	3.079	3.047
vm1_neq*	0.983	0.856
vm1_not*	0.458	0.428
vm1_rescue*	0.169	0.159
vm1_simplereturn*	1.176	1.135
vm1_swap*	0.378	0.339
vm1_yield*	1.230	1.195
vm2_array*	0.987	0.966
vm2_bigarray*	13.542	13.530
vm2_bighash*	9.129	9.163
vm2_case*	0.164	0.165
vm2_defined_method*	3.846	3.893
vm2_dstr*	2.157	2.168
vm2_eval*	24.200	23.860
vm2_method*	1.799	1.807
vm2_method_missing*	2.863	3.351
vm2_method_with_block*	1.976	1.996
vm2_mutex*	0.956	0.935
vm2_poly_method*	3.128	3.659
vm2_poly_method_ov*	0.343	0.334
vm2_proc*	0.676	0.631
vm2_raise1*	10.342	12.850
vm2_raise2*	14.914	16.689
vm2_regexp*	1.514	1.476
vm2_send*	0.455	0.505
vm2_super*	0.718	0.728
vm2_unif1*	0.270	0.305
vm2_zsuper*	0.797	0.816
vm3_backtrace	0.200	0.185
vm3_clearmethodcache	0.571	0.578
vm3_gc	1.640	1.634
vm_thread_alive_check1	0.125	0.126
vm_thread_create_join	2.268	2.255
vm_thread_mutex1	0.863	0.881
vm_thread_mutex2	1.197	1.539
vm_thread_mutex3	32.940	32.838
vm_thread_pass	0.896	0.865
vm_thread_pass_flood	0.097	0.096
vm_thread_pipe	0.798	0.801
vm_thread_queue	0.172	0.168

Speedup ratio: compare with the result of `ruby 2.2.0dev (2014-01-26 trunk 44709) [x86_64-linux]' (greater is better)
name	built-ruby
app_answer	0.981
app_aobench	0.970
app_erb	0.965
app_factorial	1.008
app_fib	0.995
app_mandelbrot	0.776
app_pentomino	0.992
app_raise	0.808
app_strconcat	0.905
app_tak	0.957
app_tarai	0.985
app_uri	0.945
hash_flatten	1.008
hash_keys	1.001
hash_shift	0.941
hash_values	1.006
io_file_create	0.879
io_file_read	0.998
io_file_write	0.976
io_select	1.023
io_select2	1.012
io_select3	0.982
loop_for	0.988
loop_generator	1.032
loop_times	0.964
loop_whileloop	0.978
loop_whileloop2	0.999
so_ackermann	0.972
so_array	0.911
so_binary_trees	0.786
so_concatenate	1.016
so_count_words	1.089
so_exception	0.818
so_fannkuch	1.002
so_fasta	1.021
so_k_nucleotide	1.190
so_lists	1.025
so_mandelbrot	0.944
so_matrix	1.012
so_meteor_contest	0.935
so_nbody	1.001
so_nested_loop	1.001
so_nsieve	0.982
so_nsieve_bits	0.858
so_object	0.955
so_partial_sums	1.069
so_pidigits	1.059
so_random	0.988
so_reverse_complement	0.969
so_sieve	0.974
so_spectralnorm	1.014
vm1_attr_ivar*	1.046
vm1_attr_ivar_set*	1.054
vm1_block*	0.983
vm1_const*	1.032
vm1_ensure*	1.279
vm1_float_simple*	1.030
vm1_gc_short_lived*	1.010
vm1_gc_short_with_complex_long*	0.994
vm1_gc_short_with_long*	1.003
vm1_gc_short_with_symbol*	1.010
vm1_gc_wb_ary*	1.009
vm1_gc_wb_obj*	1.113
vm1_ivar*	1.029
vm1_ivar_set*	1.011
vm1_length*	1.185
vm1_lvar_init*	1.062
vm1_lvar_set*	1.010
vm1_neq*	1.148
vm1_not*	1.069
vm1_rescue*	1.064
vm1_simplereturn*	1.036
vm1_swap*	1.117
vm1_yield*	1.029
vm2_array*	1.022
vm2_bigarray*	1.001
vm2_bighash*	0.996
vm2_case*	0.990
vm2_defined_method*	0.988
vm2_dstr*	0.995
vm2_eval*	1.014
vm2_method*	0.995
vm2_method_missing*	0.855
vm2_method_with_block*	0.990
vm2_mutex*	1.022
vm2_poly_method*	0.855
vm2_poly_method_ov*	1.028
vm2_proc*	1.072
vm2_raise1*	0.805
vm2_raise2*	0.894
vm2_regexp*	1.026
vm2_send*	0.900
vm2_super*	0.986
vm2_unif1*	0.887
vm2_zsuper*	0.977
vm3_backtrace	1.084
vm3_clearmethodcache	0.987
vm3_gc	1.004
vm_thread_alive_check1	0.990
vm_thread_create_join	1.006
vm_thread_mutex1	0.979
vm_thread_mutex2	0.778
vm_thread_mutex3	1.003
vm_thread_pass	1.037
vm_thread_pass_flood	1.011
vm_thread_pipe	0.996
vm_thread_queue	1.021
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/vm_method.c b/vm_method.c
index 8723a51acf..85b4b936f3 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -2,6 +2,7 @@
  * This file is included by vm.c
  */
 
+#if OPT_GLOBAL_METHOD_CACHE
 #ifndef GLOBAL_METHOD_CACHE_SIZE
 #define GLOBAL_METHOD_CACHE_SIZE 0x800
 #endif
@@ -16,6 +17,9 @@
 
 #define GLOBAL_METHOD_CACHE_KEY(c,m) ((((c)>>3)^(m))&GLOBAL_METHOD_CACHE_MASK)
 #define GLOBAL_METHOD_CACHE(c,m) (global_method_cache + GLOBAL_METHOD_CACHE_KEY(c,m))
+#else
+#define GLOBAL_METHOD_CACHE(c,m) (NULL)
+#endif
 #include "method.h"
 
 #define NOEX_NOREDEF 0
@@ -42,7 +46,10 @@ struct cache_entry {
     VALUE defined_class;
 };
 
+#if OPT_GLOBAL_METHOD_CACHE
 static struct cache_entry global_method_cache[GLOBAL_METHOD_CACHE_SIZE];
+#endif
+
 #define ruby_running (GET_VM()->running)
 /* int ruby_running = 0; */
 
@@ -574,19 +581,24 @@ rb_method_entry_get_without_cache(VALUE klass, ID id,
         defined_class = me->klass;
 
     if (ruby_running) {
-        struct cache_entry *ent;
-        ent = GLOBAL_METHOD_CACHE(klass, id);
-        ent->class_serial = RCLASS_SERIAL(klass);
-        ent->method_state = GET_GLOBAL_METHOD_STATE();
-        ent->defined_class = defined_class;
-        ent->mid = id;
+        if (OPT_GLOBAL_METHOD_CACHE) {
+            struct cache_entry *ent;
+            ent = GLOBAL_METHOD_CACHE(klass, id);
+            ent->class_serial = RCLASS_SERIAL(klass);
+            ent->method_state = GET_GLOBAL_METHOD_STATE();
+            ent->defined_class = defined_class;
+            ent->mid = id;
 
-        if (UNDEFINED_METHOD_ENTRY_P(me)) {
-            ent->me = 0;
-            me = 0;
+            if (UNDEFINED_METHOD_ENTRY_P(me)) {
+                ent->me = 0;
+                me = 0;
+            }
+            else {
+                ent->me = me;
+            }
         }
-        else {
-            ent->me = me;
+        else if (UNDEFINED_METHOD_ENTRY_P(me)) {
+            me = 0;
         }
     }
 
@@ -595,10 +607,10 @@ rb_method_entry_get_without_cache(VALUE klass, ID id,
     return me;
 }
 
-#if VM_DEBUG_VERIFY_METHOD_CACHE
 static void
 verify_method_cache(VALUE klass, ID id, VALUE defined_class, rb_method_entry_t *me)
 {
+#if VM_DEBUG_VERIFY_METHOD_CACHE
     VALUE actual_defined_class;
     rb_method_entry_t *actual_me =
         rb_method_entry_get_without_cache(klass, id, &actual_defined_class);
@@ -606,26 +618,24 @@ verify_method_cache(VALUE klass, ID id, VALUE defined_class, rb_method_entry_t *
     if (me != actual_me || defined_class != actual_defined_class) {
         rb_bug("method cache verification failed");
     }
-}
 #endif
+}
 
 rb_method_entry_t *
 rb_method_entry(VALUE klass, ID id, VALUE *defined_class_ptr)
 {
-#if OPT_GLOBAL_METHOD_CACHE
-    struct cache_entry *ent;
-    ent = GLOBAL_METHOD_CACHE(klass, id);
-    if (ent->method_state == GET_GLOBAL_METHOD_STATE() &&
-        ent->class_serial == RCLASS_SERIAL(klass) &&
-        ent->mid == id) {
-        if (defined_class_ptr)
-            *defined_class_ptr = ent->defined_class;
-#if VM_DEBUG_VERIFY_METHOD_CACHE
-        verify_method_cache(klass, id, ent->defined_class, ent->me);
-#endif
-        return ent->me;
+    if (OPT_GLOBAL_METHOD_CACHE) {
+        struct cache_entry *ent;
+        ent = GLOBAL_METHOD_CACHE(klass, id);
+        if (ent->method_state == GET_GLOBAL_METHOD_STATE() &&
+            ent->class_serial == RCLASS_SERIAL(klass) &&
+            ent->mid == id) {
+            if (defined_class_ptr)
+                *defined_class_ptr = ent->defined_class;
+            verify_method_cache(klass, id, ent->defined_class, ent->me);
+            return ent->me;
+        }
     }
-#endif
 
     return rb_method_entry_get_without_cache(klass, id, defined_class_ptr);
 }