6
lib_path = File.expand_path("../../lib", __FILE__)
10
require 'benchmark/suite'
11
require 'benchmark/ips'
20
opt = OptionParser.new do |o|
21
o.on("-t", "--target TARGET", String,
22
"Use TARGET to compare against: r:ruby|r19:ruby19|x:rbx|j:jruby") do |t|
28
when 'x', 'rbx', 'rubinius'
33
# + disambiguates execution vs using a file
38
data = Marshal.load(File.read(t))
39
compare_targets << [t, data]
49
o.on("-p", "--profile", "Profile code while benchmarking (rbx only)") do
53
o.on("-e", "--end", "Report all stats after all suitse have run") do
57
o.on("-T OPTION", String, "Add more arguments to each target") do |t|
61
o.on("-s", "--save PATH", String, "Save the results to a file") do |t|
72
if save and targets.size > 1
73
STDOUT.puts "Save mode only available with one target."
83
results = targets.map do |t|
84
tf = Tempfile.new "benchmark"
86
STDOUT.puts "=== #{t} ===" unless at_end
88
args = extra + ["-I#{lib_path}", "#{lib_path}/benchmark/suite-run.rb"]
94
cmd, *rest = t.split(/\s+/)
100
puts "Error executing: #{cmd}"
104
[t, Marshal.load(tf.read)]
111
name, data = results.last
113
File.open save, "w" do |f|
114
f << Marshal.dump(data)
117
STDOUT.puts "[Saved results to '#{save}']"
121
results.each do |name, suite|
122
STDOUT.puts "=== #{name} ==="
127
results += compare_targets
130
compared = Hash.new { |h,k| h[k] = [] }
132
results.each do |target, suite|
133
suite.reports.each do |name, reports|
134
reports.each do |rep|
135
compared["#{name}:#{rep.label}"] << [target, rep]
142
compared.each do |name, reports|
144
STDOUT.puts "Comparing #{name}:"
147
sorted = reports.sort do |a,b|
148
if a[1].respond_to? :ips
150
b[1].ips <=> a[1].ips
152
a[1].runtime <=> b[1].runtime
156
best_name, best_report = sorted.shift
160
STDOUT.printf "%20s: %10d i/s\n", best_name, best_report.ips
162
STDOUT.puts "#{best_name.rjust(20)}: #{best_report.runtime}s"
165
sorted.each do |entry|
168
x = (best_report.ips.to_f / report.ips.to_f)
169
STDOUT.printf "%20s: %10d i/s - %.2fx slower\n", name, report.ips, x
171
x = "%.2f" % (report.ips.to_f / best_report.ips.to_f)
172
STDOUT.puts "#{name.rjust(20)}: #{report.runtime}s - #{x}x slower"