#!/usr/bin/perl # stats.pl # Read STDIN and output the time/date, min, max, mean, and standard deviation # Standard deviation algorithm shamelessly stolen from Kragen Sitaker, # kragen@pobox.com # Copyright 2001 John Ackermann Version: 15 July 2001 # May be freely used provided these notices are retained, and a copy # of any modified version that's distributed to third persons is sent # to jra@febo.com $Value = 0.0; $n = 0; $Min = 0.0; $Max = 0.0; $Mean = 0.0; while ($RawIn=) { $Value = round($RawIn * 100)/100; $sum += $Value; $sumsq += $Value ** 2; $n ++; if ($n > 1) { if ($Value < $Min) {$Min = $Value} endif; if ($Value > $Max) { $Max = $Value; } endif; } else { $Min = $Value; $Max = $Value } endif; }; $Mean = round(($sum/$n)*100)/100; $StdDev = round(sqrt(($sumsq - $sum ** 2 / $n)/$n)*100)/100; print(scalar localtime(time()),"\t",$Min,"\t",$Max,"\t",$Mean,"\t",$StdDev,"\n"); sub round { my($number) = shift; return int($number +.5 * ($number <=> 0) ); };