Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 164 lines (144 sloc) 3.401 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
class TestMethod
  def empty_method
  end

  def noarg_method
    42
  end

  def args_method(a, b, c, d, e, f)
    42
  end

  def splat_method(*a)
    42
  end

  def opt_method(a, b=1, c=2, d=3, e=4)
    42
  end
end

perf_test('empty') do
  o = TestMethod.new
  i = 0
  while i < 1000000
    o.empty_method; o.empty_method; o.empty_method; o.empty_method;
    o.empty_method; o.empty_method; o.empty_method; o.empty_method;
    o.empty_method; o.empty_method; o.empty_method; o.empty_method;
    o.empty_method; o.empty_method; o.empty_method; o.empty_method;
    i += 1
  end
end

perf_test('noarg') do
  o = TestMethod.new
  i = 0
  while i < 1000000
    o.noarg_method; o.noarg_method; o.noarg_method; o.noarg_method;
    o.noarg_method; o.noarg_method; o.noarg_method; o.noarg_method;
    o.noarg_method; o.noarg_method; o.noarg_method; o.noarg_method;
    o.noarg_method; o.noarg_method; o.noarg_method; o.noarg_method;
    i += 1
  end
end

perf_test('args') do
  o = TestMethod.new
  i = 0
  while i < 1000000
    o.args_method(i, 1, i, 2, i, 3); o.args_method(i, 1, i, 2, i, 3)
    o.args_method(i, 3, i, 2, i, 1); o.args_method(i, 3, i, 2, i, 1)
    o.args_method(i, 1, i, 2, i, 3); o.args_method(i, 1, i, 2, i, 3)
    o.args_method(i, 3, i, 2, i, 1); o.args_method(i, 3, i, 2, i, 1)
    o.args_method(i, 1, i, 2, i, 3); o.args_method(i, 1, i, 2, i, 3)
    i += 1
  end
end

perf_test('msplat') do
  o = TestMethod.new
  i = 0
  while i < 200000
    o.splat_method(i)
    o.splat_method(i, i)
    o.splat_method(i, i, i)
    o.splat_method(i, i, i, i)
    o.splat_method(i, i, i, i, i)
    o.splat_method(i, i, i, i)
    o.splat_method(i, i, i)
    o.splat_method(i, i)
    o.splat_method(i)
    i += 1
  end
end

perf_test('dsplat') do
  o = TestMethod.new
  i = 0
  a = [1,2,3,4,5,6]
  while i < 1000000
    o.args_method(*a); o.args_method(*a); o.args_method(*a)
    o.args_method(*a); o.args_method(*a); o.args_method(*a)
    o.args_method(*a); o.args_method(*a); o.args_method(*a)
    o.args_method(*a); o.args_method(*a); o.args_method(*a)
    i += 1
  end
end

perf_test('opt') do
  o = TestMethod.new
  i = 0
  while i < 1000000
    o.opt_method(i)
    o.opt_method(i, i)
    o.opt_method(i, i, i)
    o.opt_method(i, i, i, i)
    o.opt_method(i, i, i, i, i)
    o.opt_method(i, i, i, i)
    o.opt_method(i, i, i)
    o.opt_method(i, i)
    o.opt_method(i)
    i += 1
  end
end

class TestPolyMethod1
  def foo; 1; end
end

class TestPolyMethod2
  def foo; 2; end
end

class TestPolyMethod3 < TestPolyMethod1
  def foo; 3; end
end

class TestPolyMethod4 < TestPolyMethod2
  def foo; 4; end
end

perf_test('poly') do
  o1 = TestPolyMethod1.new
  o2 = TestPolyMethod2.new
  o3 = TestPolyMethod3.new
  o4 = TestPolyMethod4.new
  i = 0
  while i < 1000000
    o1.foo; o2.foo; o3.foo; o4.foo
    o1.foo; o2.foo; o3.foo; o4.foo
    o1.foo; o2.foo; o3.foo; o4.foo
    o1.foo; o2.foo; o3.foo; o4.foo
    i += 1
  end
end

class TestSuper1
  def foo; 42; end
end

class TestSuper2 < TestSuper1
  def foo; super; end
end

class TestSuper3 < TestSuper2
  def foo; super; end
end

class TestSuper4 < TestSuper3
  def foo; super; end
end

perf_test('super') do
  o4 = TestSuper4.new
  o3 = TestSuper3.new
  i = 0
  while i < 10000
    o4.foo; o3.foo; o4.foo; o3.foo
    o4.foo; o3.foo; o4.foo; o3.foo
    o4.foo; o3.foo; o4.foo; o3.foo
    o4.foo; o3.foo; o4.foo; o3.foo
    i += 1
  end
end
Something went wrong with that request. Please try again.