Class: Stats::TimingStat

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

Instance Method Summary collapse

Instance Method Details

#avgObject

Returns the average value.



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

def avg
  return nil if length == 0
  sum / length.to_f
end

#pop_varObject

Returns the population variance of the values.



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

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

#std_devObject

Returns the standard deviation of the values.



17
18
19
20
# File 'lib/stats/timing_stat.rb', line 17

def std_dev
  return nil if length == 0
  Math.sqrt(pop_var)
end