From owner-freebsd-current Wed Nov 1 10:05:06 1995 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id KAA23849 for current-outgoing; Wed, 1 Nov 1995 10:05:06 -0800 Received: from halloran-eldar.lcs.mit.edu (halloran-eldar.lcs.mit.edu [18.26.0.159]) by freefall.freebsd.org (8.6.12/8.6.6) with SMTP id KAA23844 for ; Wed, 1 Nov 1995 10:05:04 -0800 Received: by halloran-eldar.lcs.mit.edu; (5.65/1.1.8.2/19Aug95-0530PM) id AA01541; Wed, 1 Nov 1995 13:01:55 -0500 Date: Wed, 1 Nov 1995 13:01:55 -0500 From: "Garrett A. Wollman" Message-Id: <9511011801.AA01541@halloran-eldar.lcs.mit.edu> To: Bruce Evans Cc: current@FreeBSD.org Subject: Re: Time problems In-Reply-To: <199511011730.EAA07621@godzilla.zeta.org.au> References: <199511011730.EAA07621@godzilla.zeta.org.au> Sender: owner-current@FreeBSD.org Precedence: bulk < said: > much less than the average value mean that there is a problem. The > program should calculate the average value to decide a good range to > filter... Here is a program that I have used to measure a whole bunch of things about the clock... ------------------------------------ #include #include #include #include #include #include #include #include #define N 2000000 int diffs[N]; int hist[N]; int main(void) { int i, j; int min, max; double sum, mean, var, sumsq; struct timeval tv, otv; memset(diffs, '\0', sizeof diffs); /* fault in whole array, we hope */ for(i = 0; i < N; i++) { gettimeofday(&tv, 0); do { otv = tv; gettimeofday(&tv, 0); } while(tv.tv_sec == otv.tv_sec && tv.tv_usec == otv.tv_usec); diffs[i] = tv.tv_usec - otv.tv_usec + 1000000 * (tv.tv_sec - otv.tv_sec); } min = INT_MAX; max = INT_MIN; sum = 0; sumsq = 0; for(i = 0; i < N; i++) { if(diffs[i] > max) max = diffs[i]; if(diffs[i] < min) min = diffs[i]; sum += diffs[i]; sumsq += diffs[i] * diffs[i]; } mean = sum / (double)N; var = (sumsq - 2 * mean * sum + sum * mean) / (double)N; printf("min %d, max %d, mean %f, std %f\n", min, max, mean, sqrt(var)); for(i = 0; i < N; i++) { hist[diffs[i]]++; } for(j = 0; j < 5; j++) { max = 0; min = 0; for(i = 0; i < N; i++) { if(hist[i] > max) { max = hist[i]; min = i; /* xxx */ } } printf("%dth: %d (%d observations)\n", j + 1, min, max); hist[min] = 0; } return 0; } ------------------------------------ -GAWollman -- Garrett A. Wollman | Shashish is simple, it's discreet, it's brief. ... wollman@lcs.mit.edu | Shashish is the bonding of hearts in spite of distance. Opinions not those of| It is a bond more powerful than absence. We like people MIT, LCS, ANA, or NSA| who like Shashish. - Claude McKenzie + Florent Vollant