Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Nov 1995 13:01:55 -0500
From:      "Garrett A. Wollman" <wollman@lcs.mit.edu>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        current@FreeBSD.org
Subject:   Re: Time problems
Message-ID:  <9511011801.AA01541@halloran-eldar.lcs.mit.edu>
In-Reply-To: <199511011730.EAA07621@godzilla.zeta.org.au>
References:  <199511011730.EAA07621@godzilla.zeta.org.au>

next in thread | previous in thread | raw e-mail | index | archive | help
<<On Thu, 2 Nov 1995 04:30:41 +1100, Bruce Evans <bde@zeta.org.au> 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 <sys/types.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <math.h>
#include <limits.h>
#include <string.h>

#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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9511011801.AA01541>