Class: Stats::TimingStat
- Inherits:
-
Array
- Object
- Array
- Stats::TimingStat
- Defined in:
- lib/stats/timing_stat.rb
Instance Method Summary collapse
-
#avg ⇒ Object
Returns the average value.
-
#pop_var ⇒ Object
Returns the population variance of the values.
-
#std_dev ⇒ Object
Returns the standard deviation of the values.
Instance Method Details
#avg ⇒ Object
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_var ⇒ Object
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_dev ⇒ Object
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 |