Class: Benchmark::IPS::Stats::Bootstrap
- Inherits:
-
Object
- Object
- Benchmark::IPS::Stats::Bootstrap
- Includes:
- StatsMetric
- Defined in:
- lib/benchmark/ips/stats/bootstrap.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#samples ⇒ Object
readonly
Returns the value of attribute samples.
Instance Method Summary collapse
-
#central_tendency ⇒ Float
Average stat value.
- #dependencies ⇒ Object
- #footer ⇒ Object
-
#initialize(samples, confidence) ⇒ Bootstrap
constructor
A new instance of Bootstrap.
-
#slowdown(baseline) ⇒ Object
Determines how much slower this stat is than the baseline stat if this average is lower than the faster baseline, higher average is better (e.g. ips) (calculate accordingly).
- #speedup(baseline) ⇒ Object
Methods included from StatsMetric
Constructor Details
#initialize(samples, confidence) ⇒ Bootstrap
Returns a new instance of Bootstrap.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 9 def initialize(samples, confidence) dependencies @iterations = 10_000 @confidence = (confidence / 100.0).to_s @samples = samples @data = Kalibera::Data.new({[0] => samples}, [1, samples.size]) interval = @data.bootstrap_confidence_interval(@iterations, @confidence) @median = interval.median @error = interval.error end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 7 def data @data end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 7 def error @error end |
#samples ⇒ Object (readonly)
Returns the value of attribute samples.
7 8 9 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 7 def samples @samples end |
Instance Method Details
#central_tendency ⇒ Float
Average stat value
22 23 24 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 22 def central_tendency @median end |
#dependencies ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 44 def dependencies require 'kalibera' rescue LoadError puts puts "Can't load the kalibera gem - this is required to use the :bootstrap stats options." puts "It's optional, so we don't formally depend on it and it isn't installed along with benchmark-ips." puts "You probably want to do something like 'gem install kalibera' to fix this." abort end |
#footer ⇒ Object
40 41 42 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 40 def "with #{(@confidence.to_f * 100).round(1)}% confidence" end |
#slowdown(baseline) ⇒ Object
Determines how much slower this stat is than the baseline stat if this average is lower than the faster baseline, higher average is better (e.g. ips) (calculate accordingly)
30 31 32 33 34 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 30 def slowdown(baseline) low, slowdown, high = baseline.data.bootstrap_quotient(@data, @iterations, @confidence) error = Timing.mean([slowdown - low, high - slowdown]) [slowdown, error] end |
#speedup(baseline) ⇒ Object
36 37 38 |
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 36 def speedup(baseline) baseline.slowdown(self) end |