Class: Stud::Benchmark::Results
- Inherits:
-
Object
- Object
- Stud::Benchmark::Results
- Includes:
- Enumerable
- Defined in:
- lib/stud/benchmark.rb
Overview
self.cpu
Constant Summary collapse
- TICKS =
Stolen from github.com/holman/spark/blob/master/spark TICKS = %w▂ ▃ ▄ ▅ ▆ ▇ █
["\x1b[38;5;#{232 + 8}m_\x1b[0m"] + %w{▁ ▂ ▃ ▄ ▅ ▆ ▇ █}
Instance Method Summary collapse
-
#each(&block) ⇒ Object
def environment.
-
#environment ⇒ Object
def initialize.
-
#initialize(data, duration) ⇒ Results
constructor
end.flatten.
- #max ⇒ Object
- #mean ⇒ Object
-
#min ⇒ Object
def each.
-
#pretty_print ⇒ Object
def sum.
- #rate ⇒ Object
-
#stddev ⇒ Object
def mean.
-
#sum ⇒ Object
def stddev.
-
#to_s(scale = min .. max, ticks = 10) ⇒ Object
def pretty_print.
Constructor Details
#initialize(data, duration) ⇒ Results
end.flatten
65 66 67 68 |
# File 'lib/stud/benchmark.rb', line 65 def initialize(data, duration) @data = data @duration = duration end |
Instance Method Details
#each(&block) ⇒ Object
def environment
80 81 82 |
# File 'lib/stud/benchmark.rb', line 80 def each(&block) @data.snapshot.each(&block) end |
#environment ⇒ Object
def initialize
70 71 72 73 74 75 76 77 78 |
# File 'lib/stud/benchmark.rb', line 70 def environment # Older rubies don't have the RUBY_ENGINE defiend engine = (RUBY_ENGINE rescue "ruby") # Include jruby version in the engine engine += (JRUBY_VERSION rescue "") version = RUBY_VERSION return "#{engine} #{version}" end |
#max ⇒ Object
88 89 90 |
# File 'lib/stud/benchmark.rb', line 88 def max return @data.max end |
#mean ⇒ Object
96 97 98 |
# File 'lib/stud/benchmark.rb', line 96 def mean return @data.mean end |
#min ⇒ Object
def each
84 85 86 |
# File 'lib/stud/benchmark.rb', line 84 def min return @data.min end |
#pretty_print ⇒ Object
def sum
110 111 112 |
# File 'lib/stud/benchmark.rb', line 110 def pretty_print puts self end |
#rate ⇒ Object
92 93 94 |
# File 'lib/stud/benchmark.rb', line 92 def rate return @data.count / @duration end |
#stddev ⇒ Object
def mean
100 101 102 103 104 |
# File 'lib/stud/benchmark.rb', line 100 def stddev # work around (Timer#stddev reports the variance) # https://github.com/eric/metriks/pull/29 return @data.stddev ** 0.5 end |
#sum ⇒ Object
def stddev
106 107 108 |
# File 'lib/stud/benchmark.rb', line 106 def sum return @data.instance_eval { @histogram.sum } end |
#to_s(scale = min .. max, ticks = 10) ⇒ Object
def pretty_print
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/stud/benchmark.rb', line 114 def to_s(scale=min .. max, ticks=10) snapshot = @data.snapshot values = snapshot.instance_eval { @values } scale_distance = scale.end - scale.begin tick = scale_distance / ticks dist = ticks.to_i.times.collect do |i| range = (scale.begin + tick * i) ... (scale.begin + tick * (i+1)) hits = values.select { |v| range.include?(v) }.count percent = hits / values.size.to_f next TICKS[(TICKS.count * percent).ceil] || TICKS.last end return sprintf("%20s %s (%.4f ... %.4f, mean: %0.4f, stddev: %0.4f)", environment, dist.join(""), scale.begin, scale.end, mean, stddev) end |