Class: Stats::TimingStat

Inherits:
Array
  • Object
show all
Defined in:
lib/stats/timing_stat.rb

Instance Method Summary collapse

Instance Method Details

#averageObject

Returns the average value.



4
5
6
# File 'lib/stats/timing_stat.rb', line 4

def average
  sum / length.to_f
end

#population_varianceObject

Returns the sample variance of the values.



9
10
11
12
# File 'lib/stats/timing_stat.rb', line 9

def population_variance
  avg = average
  1 / length.to_f * inject(0) { |acc, i| acc + (i - avg) ** 2 }
end

#standard_deviationObject

Returns the standard deviation of the values.



15
16
17
# File 'lib/stats/timing_stat.rb', line 15

def standard_deviation
  Math.sqrt(population_variance)
end