1
2require './rbconfig'
3require 'fileutils'
4require 'pp'
5
6Ruby = ENV['RUBY'] || RbConfig.ruby
7#
8
9OPTIONS = %w{
10 opt-direct-threaded-code
11 opt-basic-operations
12 opt-operands-unification
13 opt-instructions-unification
14 opt-inline-method-cache
15 opt-stack-caching
16}.map{|opt|
17  '--disable-' + opt
18}
19
20opts = OPTIONS.dup
21Configs = OPTIONS.map{|opt|
22  o = opts.dup
23  opts.delete(opt)
24  o
25} + [[]]
26
27pp Configs if $DEBUG
28
29
30def exec_cmd(cmd)
31  puts cmd
32  unless system(cmd)
33    p cmd
34    raise "error"
35  end
36end
37
38def dirname idx
39  "ev-#{idx}"
40end
41
42def build
43  Configs.each_with_index{|config, idx|
44    dir = dirname(idx)
45    FileUtils.rm_rf(dir) if FileTest.exist?(dir)
46    Dir.mkdir(dir)
47    FileUtils.cd(dir){
48      exec_cmd("#{Ruby} ../extconf.rb " + config.join(" "))
49      exec_cmd("make clean test-all")
50    }
51  }
52end
53
54def check
55  Configs.each_with_index{|c, idx|
56    puts "= #{idx}"
57    system("#{Ruby} -r ev-#{idx}/yarvcore -e 'puts YARVCore::OPTS'")
58  }
59end
60
61def bench_each idx
62  puts "= #{idx}"
63  5.times{|count|
64    print count
65    FileUtils.cd(dirname(idx)){
66      exec_cmd("make benchmark OPT=-y ITEMS=#{ENV['ITEMS']} > ../b#{idx}-#{count}")
67    }
68  }
69  puts
70end
71
72def bench
73  # return bench_each(6)
74  Configs.each_with_index{|c, idx|
75    bench_each idx
76  }
77end
78
79def parse_result data
80  flag = false
81  stat = []
82  data.each{|line|
83    if flag
84      if /(\w+)\t([\d\.]+)/ =~ line
85        stat << [$1, $2.to_f]
86      else
87        raise "not a data"
88      end
89
90    end
91    if /benchmark summary/ =~ line
92      flag = true
93    end
94  }
95  stat
96end
97
98def calc_each data
99  data.sort!
100  data.pop   # remove max
101  data.shift # remove min
102
103  data.inject(0.0){|res, e|
104    res += e
105  } / data.size
106end
107
108def calc_stat stats
109  stat = []
110  stats[0].each_with_index{|e, idx|
111    bm = e[0]
112    vals = stats.map{|st|
113      st[idx][1]
114    }
115    [bm, calc_each(vals)]
116  }
117end
118
119def stat
120  total = []
121  Configs.each_with_index{|c, idx|
122    stats = []
123    5.times{|count|
124      file = "b#{idx}-#{count}"
125      # p file
126      open(file){|f|
127        stats << parse_result(f.read)
128      }
129    }
130    # merge stats
131    total << calc_stat(stats)
132    total
133  }
134  # pp total
135  total[0].each_with_index{|e, idx|
136    bm = e[0]
137    # print "#{bm}\t"
138    total.each{|st|
139      print st[idx][1], "\t"
140    }
141    puts
142  }
143end
144
145ARGV.each{|cmd|
146  case cmd
147  when 'build'
148    build
149  when 'check'
150    check
151  when 'bench'
152    bench
153  when 'stat'
154    stat
155  else
156    raise
157  end
158}
159
160