Skip to content

Commit

Permalink
Add stddev to rlikestats.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
mat committed Jul 29, 2012
1 parent c93ae62 commit 3318f19
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bin/rlikestats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# 95th Pct.: 2.1000
# 99th Pct.: 2.1000
# Max : 2.1000
# Stddev : 0.5395


class Rlikestats
Expand All @@ -28,6 +29,7 @@ def initialize
self.count = 0
self.mean = 0.0
self.lines = 0
self.m2 = 0.0
end

def run
Expand All @@ -39,9 +41,15 @@ def run
end
val = line.to_f
self.count += 1
self.mean += (val - mean) / count

delta = val - mean
self.mean = mean + delta / count
self.m2 = m2 + delta * (val - mean)

values << val
end
variance = m2 / (count - 1)
self.stddev = Math.sqrt(variance)

values.sort!
print_result
Expand All @@ -62,7 +70,11 @@ def print_result
puts "95th Pct.: %12.4f" % percentile(0.95)
puts "99th Pct.: %12.4f" % percentile(0.99)
puts "Max : %12.4f" % values.last
puts "Stddev : %12.4f" % stddev
end

private
attr_accessor :m2, :stddev
end

Rlikestats.new.run

0 comments on commit 3318f19

Please sign in to comment.