Object
A Comparison instance compares the benchmark results of different case methods and outputs the results.
Benchmark case method method of bc_class. Options are:
# File lib/bullshit.rb, line 2112 def benchmark(bc_class, method, opts = {}) opts = { :run => true, :combine => true }.merge opts if Case === bc_class bullshit_case, bc_class = bc_class, bc_class.class @cases[bc_class] ||= [] if opts[:combine] if @cases[bc_class].empty? @cases[bc_class] << bullshit_case else bullshit_case = @cases[bc_class].first end else @cases[bc_class] << bullshit_case end else @cases[bc_class] ||= [] if opts[:combine] unless bullshit_case = @cases[bc_class].first bullshit_case = bc_class.new @cases[bc_class] << bullshit_case end else bullshit_case = bc_class.new @cases[bc_class] << bullshit_case end end bc_method = bullshit_case[method] or raise BullshitException, "unknown benchmark method #{bc_class}##{method}" if comment = opts[:comment] bc_method.comment = comment end if file_path = opts[:load] success = if file_path != true bc_method.load(file_path) else bc_method.load end if success @benchmark_methods << bc_method else warn "Loading of #{bc_method} failed. Skipping to next." end else opts[:run] and bullshit_case.run false @benchmark_methods << bc_method end nil end
Return all benchmark methods ordered by the result of comparator call to their clock values.
# File lib/bullshit.rb, line 2166 def compare_methods(comparator) benchmark_methods.sort_by { |m| m.clock.__send__(comparator) } end
Output all speed comparisons between methods.
# File lib/bullshit.rb, line 2182 def display output.puts Time.now.strftime(' %FT%T %Z ').center(COLUMNS, '=') for comparator in [ :call_time_mean, :call_time_median ] output.puts cmethods = compare_methods(comparator) cmethods.size < 2 and return max = cmethods.last.clock.__send__(comparator) output.puts "Comparing times (#{comparator}):" cmethods.each_with_index do |m, i| output.printf\ "% 2u #{prefix_string(m)}\n %17.9f"\ " (%#{::Bullshit::Clock::TIMES_MAX}s) %s\n"\ " %17.9f %8.2f %17.9f\n", i + 1, m.clock.calls(comparator), m.case.class.compare_time, compute_covers(cmethods, m), m.clock.__send__(comparator), m.clock.sample_standard_deviation_percentage(m.case.class.compare_time), m.clock.sum(m.case.class.compare_time) end output.puts " %17s (%#{::Bullshit::Clock::TIMES_MAX}s) %s\n"\ " %17s %8s %17s\n"\ % %w[calls/sec time covers secs/call std% sum] display_speedup_matrix(cmethods, comparator) end output.puts '=' * COLUMNS end
Return the length of the longest name of all benchmark methods.
# File lib/bullshit.rb, line 2171 def longest_name_size benchmark_methods.map { |m| m.long_name.size }.max end
Output results to the file named name.
# File lib/bullshit.rb, line 2095 def output_filename(name) path = File.expand_path(name, output_dir) output File.new(path, 'a+') end
Returns the prefix_string for a method speed comparison in the output.
# File lib/bullshit.rb, line 2176 def prefix_string(method) "% -#{longest_name_size}s %u repeats:" % [ method.long_name , method.clock.repeat ] end
(Not documented)
# File lib/bullshit.rb, line 2227 def compute_covers(cmethods, m) covers = [] for x in cmethods if m != x and m.cover?(x) j = 0 if cmethods.find { |y| j += 1; x == y } my_case = m.case.class iterations = m.clock.analysis[my_case.compare_time].suggested_sample_size( x.clock.analysis[my_case.compare_time], my_case.covering.alpha_level, my_case.covering.beta_level) if iterations.nan? or iterations.infinite? covers << "#{j} (?)" else min_iterations = iterations.ceil min_iterations >= 1E6 and min_iterations = "%f" % (1 / 0.0) covers << "#{j} (>=#{min_iterations})" end end end end covers * ', ' end
(Not documented)
# File lib/bullshit.rb, line 2210 def display_speedup_matrix(cmethods, comparator) output.print "\n", " " * 3 cmethods.size.times do |i| output.printf "%7d ", i + 1 end output.puts cmethods.each_with_index do |x, i| output.printf "%2d ", i + 1 cmethods.each do |y| ratio = x.clock.calls(comparator).to_f / y.clock.calls(comparator) ratio /= 0.0 if ratio >= 1000 output.printf "%7.2f ", ratio end output.puts end end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.