File: sd.rb

package info (click to toggle)
ruby-benchmark-ips 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 224 kB
  • sloc: ruby: 1,257; makefile: 11
file content (45 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Benchmark
  module IPS
    module Stats

      class SD
        include StatsMetric
        attr_reader :error, :samples

        def initialize(samples)
          @samples = samples
          @mean = Timing.mean(samples)
          @error = Timing.stddev(samples, @mean).round
        end

        # Average stat value
        # @return [Float] central_tendency
        def central_tendency
          @mean
        end

        # 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)
        # @param baseline [SD|Bootstrap] faster baseline
        # @returns [Array<Float, nil>] the slowdown and the error (not calculated for standard deviation)
        def slowdown(baseline)
          if baseline.central_tendency > central_tendency
            [baseline.central_tendency.to_f / central_tendency, nil]
          else
            [central_tendency.to_f / baseline.central_tendency, nil]
          end
        end

        def speedup(baseline)
          baseline.slowdown(self)
        end

        def footer
          nil
        end

      end

    end
  end
end