Class: Benchmark::IPS::Stats::Bootstrap

Inherits:
Object
  • Object
show all
Includes:
StatsMetric
Defined in:
lib/benchmark/ips/stats/bootstrap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StatsMetric

#error_percentage, #overlaps?

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

#dataObject (readonly)

Returns the value of attribute data


7
8
9
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 7

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error


7
8
9
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 7

def error
  @error
end

#samplesObject (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_tendencyFloat

Average stat value

Returns:

  • (Float)

    central_tendency


22
23
24
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 22

def central_tendency
  @median
end

#dependenciesObject


40
41
42
43
44
45
46
47
48
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 40

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

36
37
38
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 36

def footer
  "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)

Parameters:


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