Class Stats
In: lib/mongrel/stats.rb
Parent: Object

A very simple little class for doing some basic fast statistics sampling. You feed it either samples of numeric data you want measured or you call Stats.tick to get it to add a time delta between the last time you called it. When you’re done either call sum, sumsq, n, min, max, mean or sd to get the information. The other option is to just call dump and see everything.

It does all of this very fast and doesn’t take up any memory since the samples are not stored but instead all the values are calculated on the fly.

Methods

dump   mean   new   reset   sample   sd   tick   to_s  

Attributes

max  [R] 
min  [R] 
n  [R] 
sum  [R] 
sumsq  [R] 

Public Class methods

Public Instance methods

Dump this Stats object with an optional additional message.

Calculates and returns the mean for the data passed so far.

Resets the internal counters so you can start sampling again.

Adds a sampling to the calculations.

Calculates the standard deviation of the data so far.

Adds a time delta between now and the last time you called this. This will give you the average time between two activities.

An example is:

 t = Stats.new("do_stuff")
 10000.times { do_stuff(); t.tick }
 t.dump("time")

Returns a common display (used by dump)

[Validate]