Project

General

Profile

Feature #15085 ยป super.rb

wanabe (_ wanabe), 09/06/2018 10:59 PM

 
1
require 'benchmark_driver'
2
max = 40
3

    
4
Benchmark.driver do |x|
5
  prelude = <<~RUBY
6
    class A0
7
      def foo
8
      end
9
    
10
      def foo0
11
      end
12
    end
13
  RUBY
14
    
15
  i = 0
16
  while i < max
17
    i += 1
18
    prelude << <<~RUBY
19
      class A#{i} < A#{i - 1}
20
        def foo
21
          super
22
        end
23
        def foo#{i}
24
          foo#{i - 1}
25
        end
26
      end
27
    RUBY
28
  end
29

    
30
  prelude << <<~RUBY
31
    if RubyVM::MJIT.enabled?
32
      a = eval("A#{max}").new
33
      10.times { a.foo }
34
      RubyVM::MJIT.pause
35
    end
36

    
37
    a = A#{max}.new
38
  RUBY
39

    
40
  if ENV["PERF_STAT"]
41
    puts "perf stat target: #{ENV["PERF_STAT"]}"
42
    prelude << <<~RUBY
43
      $pid = Process.spawn("perf stat -e #{ENV["PERF_STAT"]} -p \#{$$}")
44
      at_exit { Process.kill :INT, $pid }
45
    RUBY
46
  end
47

    
48
  x.rbenv 'trunk', 'trunk,--jit', 'export-big-func', 'export-big-func,--jit'
49
  x.prelude prelude
50

    
51
  x.report %{ a.foo }
52
end
53