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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(samples, confidence) ⇒ Bootstrap

Returns a new instance of Bootstrap.



9
10
11
12
13
14
15
16
17
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 9

def initialize(samples, confidence)
  dependencies
  @iterations = 10_000
  @confidence = (confidence / 100.0).to_s
  @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

Instance Method Details

#central_tendencyObject



19
20
21
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 19

def central_tendency
  @median
end

#dependenciesObject



37
38
39
40
41
42
43
44
45
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 37

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

#errorObject



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

def error
  @error
end


33
34
35
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 33

def footer
  "with #{(@confidence.to_f * 100).round(1)}% confidence"
end

#slowdown(baseline) ⇒ Object



27
28
29
30
31
# File 'lib/benchmark/ips/stats/bootstrap.rb', line 27

def slowdown(baseline)
  low, slowdown, high = baseline.data.bootstrap_quotient(@data, @iterations, @confidence)
  error = Timing.mean([slowdown - low, high - slowdown])
  [slowdown, error]
end