class Benchmark::Sweet::Comparison
Constants
- UNITS
Attributes
baseline[R]
label[R]
metric[R]
offset[R]
stats[R]
total[R]
worst[R]
Public Class Methods
new(metric, label, stats, offset, total, baseline, worst = nil)
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 7 def initialize(metric, label, stats, offset, total, baseline, worst = nil) @metric = metric @label = label @stats = stats @offset = offset @total = total @baseline = baseline @worst = worst end
Public Instance Methods
[](field)
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 17 def [](field) case field when :metric then metric when :comp_short then comp_short when :comp_string then comp_string when :label then label # not sure if this one makes sense else label[field] end end
best?()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 35 def best? ; !baseline || (baseline == stats) ; end
central_tendency()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 27 def central_tendency ; stats.central_tendency ; end
color()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 92 def color if !baseline ";0" elsif best? || overlaps? "32" elsif worst? "31" else ";0" end end
comp_short(value = nil)
click to toggle source
I tend to call with:
c.comp_short("\033[#{c.color}m#{c.central_tendency.round(1)} #{c.units}\e[0m") # "\033[31m#{value}\e[0m"
# File lib/benchmark/sweet/comparison.rb, line 80 def comp_short(value = nil) value ||= "#{central_tendency.round(1)} #{units}" case mode when :best, :same value when :slower "%s - %.2fx (± %.2f)" % [value, slowdown, error] when :slowerish "%s - %.2fx" % [value, slowdown] end end
comp_string(l_to_s = nil)
click to toggle source
quick display
# File lib/benchmark/sweet/comparison.rb, line 64 def comp_string(l_to_s = nil) l_to_s ||= -> l { l.to_s } case mode when :best "%20s: %10.1f %s" % [l_to_s.call(label), central_tendency, units] when :same "%20s: %10.1f %s - same-ish: difference falls within error" % [l_to_s.call(label), central_tendency, units] when :slower "%20s: %10.1f %s - %.2fx (± %.2f) slower" % [l_to_s.call(label), central_tendency, units, slowdown, error] when :slowerish "%20s: %10.1f %s - %.2fx slower" % [l_to_s.call(label), central_tendency, units, slowdown] end end
diff_error()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 58 def diff_error @diff_error ||= (slowdown ; @diff_error) end
error()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 28 def error ; stats.error ; end
mode()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 31 def mode @mode ||= best? ? :best : overlaps? ? :same : diff_error ? :slowerish : :slower end
overlaps?()
click to toggle source
@return true if it is basically the same as the best
# File lib/benchmark/sweet/comparison.rb, line 38 def overlaps? return @overlaps if defined?(@overlaps) @overlaps = slowdown == 1 || stats && baseline && (stats.central_tendency == baseline.central_tendency || stats.overlaps?(baseline)) end
slowdown()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 52 def slowdown return @slowdown if @slowdown @slowdown, @diff_error = stats.slowdown(baseline) @slowdown end
units()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 29 def units ; UNITS[metric] || "objs" ; end
worst?()
click to toggle source
# File lib/benchmark/sweet/comparison.rb, line 44 def worst? if @worst stats.overlaps?(@worst) else slowdown == Float::INFINITY || (total.to_i - 1 == offset.to_i && slowdown.to_i > 1) end end