Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src



On Wed, Feb 24, 1999 at 11:31:38AM -0800, Jim Wise wrote:
> Module Name:  src
> Committed By: jwise
> Date:         Wed Feb 24 19:31:38 UTC 1999
> 
> Modified Files:
>       src/sbin/ping: Makefile ping.c
> Log Message:
> Add code from Daniel Hagerty <hag%ai.mit.edu@localhost> to print standard 
> deviation
> when printing out final statistics line.
> 
> Closes PR bin/6198

  There are a few problems with the code in the PR.  I thought I
had CC'd netbsd-bugs on my note to Daniel back in September,
but apparently not, and he never replied.

  Problem 1:  The equation for the variance is wrong.  It ought to be:
double variance = ((tsumsq/n) - avg*avg) * (n/(n-1));
  Try it out with two samples of 1e-3 and 1e-3, and the variance
ought to be 0, and not 1e-6 as the current code produces.

  Problem 2:  Scaling is wrong.  In the printf, we print
sqrt(variance*1000), but that should be sqrt(variance)*1000.


  I've verified the correctness of this by using the octave
stddev builtin (std) to calculate the stddev of the sample
times.  Here's a diff, if you want to commit, or I can if there
are no objections (and Luke/Matthew agree).

RCS file: /ccd0/cvsroot/src/sbin/ping/ping.c,v
retrieving revision 1.44
diff -1 -u -t -p -r1.44 ping.c
--- ping.c  1999/02/24 19:31:38     1.44
+++ ping.c  1999/02/25 02:52:22
@@ -1113,3 +1113,3 @@ summary(int header)
                 double avg = (tsum / n);
-                double variance = (tsumsq / (n - (avg * avg)));
+                double variance = ((tsumsq/n) - avg*avg) * (n/(n-1));
 
@@ -1118,3 +1118,3 @@ summary(int header)
                         tmin * 1000.0, avg * 1000.0,
-                        tmax * 1000.0, sqrt(variance * 1000.0));
+                        tmax * 1000.0, sqrt(variance) * 1000.0);
                 if (pingflags & F_FLOOD) {



Home | Main Index | Thread Index | Old Index