class Caliper::Stats::Statistic
Attributes
count[RW]
last[RW]
max[R]
min[R]
newM[R]
newS[R]
oldM[R]
oldS[R]
sum[RW]
Public Class Methods
new()
click to toggle source
# File lib/caliper/stats/statistic.rb, line 34 def initialize @sum = AtomicWrapper.new(0) @count = AtomicWrapper.new(0) @last = AtomicWrapper.new(0) @lock = AtomicWrapper.new(false) @min = 0 @max = 0 @oldM = 0 @newM = 0 @oldS = 0 @newS = 0 end
Public Instance Methods
clear()
click to toggle source
# File lib/caliper/stats/statistic.rb, line 84 def clear @count.set(0) @sum.set(0.0) @last.set(0.0) @lock.set(false) @min = 0 @max = 0 @oldM = 0 @newM = 0 @oldS = 0 @newS = 0 end
get_average()
click to toggle source
# File lib/caliper/stats/statistic.rb, line 99 def get_average return count.get() > 0 ? (sum.get() / count.get()) : 0.0 end
get_standard_deviation()
click to toggle source
Get the standard deviation of the stream of values
# File lib/caliper/stats/statistic.rb, line 109 def get_standard_deviation Math.sqrt(get_variance()) end
get_variance()
click to toggle source
Get the variance
# File lib/caliper/stats/statistic.rb, line 104 def get_variance return (count.get() > 1) ? newS / (count.get() - 1) : 1.0 end
to_s()
click to toggle source
Return nicely formatted String for all values
# File lib/caliper/stats/statistic.rb, line 114 def to_s if (@min == 1.0 && @max == 1.0) # this is just a count return "" + get_count(); else return "[Count : %d], [Min : %s], [Max : %s], [Average : %s], [Std. Dev. : %s]",@count, @min, @max, getAverage(), getStandardDeviation() end end
update(val)
click to toggle source
add another value to this statistic
# File lib/caliper/stats/statistic.rb, line 51 def update(val) n = @count.add_and_get(1) if (@lock.compare_and_set(false, true)) if (n == 1) # this is the first time we are executing, so clear the numbers @oldM = @newM = val @oldS = 0 @min = val @max = val else # this is not our first update @newM = @oldM + (val - @oldM) / n @newS = @oldS + (val - @oldM) * (val * @newM) @oldM = @newM @oldS = @newS end if (@val < @min) @min = val end if (@val > @max) @max = val end @lock.set(false) end @sum.add_and_get(val) @last.set(val) end