home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / musbus / part02 / clock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-16  |  1.8 KB  |  93 lines

  1. /*
  2.  *  clock -- check alarm signal accuracy
  3.  *
  4.  *  $Header: clock.c,v 3.4 87/06/22 14:22:54 kjmcdonell Beta $
  5.  */
  6.  
  7. #include <signal.h>
  8. #include <stdio.h>
  9. #include <sys/types.h>
  10. #ifdef BSD4v1
  11. #include <sys/timeb.h>
  12. #endif
  13. #ifdef BSD4v2
  14. #include <sys/time.h>
  15. #endif
  16. #ifdef SysV
  17. #include <sys/times.h>
  18. #include <sys/param.h>
  19. #ifdef interdata
  20. #define HZ tbuffer.tms_cfreq
  21. #endif
  22. #ifndef HZ
  23.     On your system, what is the value of HZ for high resolution elapsed
  24.     time as returned by times() or its equivalent?
  25. #endif
  26. #endif
  27.  
  28. #define GRANULE        5
  29. #define NUM_ALRM    12
  30.  
  31. main(argc, argv)
  32. int    argc;
  33. char    *argv[];
  34. {
  35.     int            onalarm();
  36.     register int    i = 0;
  37.     int            expected;
  38.     float        wallclock;
  39.     long        then;
  40. #ifdef SysV
  41.     struct tms        tbuffer;
  42. #endif
  43. #ifdef BSD4v1
  44.     struct timeb    tbuf;
  45.     int            msec;
  46. #endif
  47. #ifdef BSD4v2
  48.     struct timeval    tval;
  49.     struct timezone    tzone;
  50.     long        usec;
  51. #endif
  52.  
  53. #ifdef SysV
  54.     then = times(&tbuffer);
  55. #else
  56. #ifdef BSD4v1
  57.     ftime(&tbuf);
  58.     then = tbuf.time;
  59.     msec = tbuf.millitm;
  60. #else
  61. #ifdef BSD4v2
  62.     gettimeofday(&tval, &tzone);
  63.     then = tval.tv_sec;
  64.     usec = tval.tv_usec;
  65. #else
  66.     What sort of Unix system is this?
  67. #endif
  68. #endif
  69. #endif
  70.     while (i++ < NUM_ALRM) {
  71.         signal(SIGALRM, onalarm);
  72.         alarm(GRANULE);
  73.         pause();
  74.     }
  75. #ifdef SysV
  76.     wallclock = (times(&tbuffer) - then)/HZ;
  77. #endif
  78. #ifdef BSD4v1
  79.     ftime(&tbuf);
  80.     wallclock = tbuf.time - then + (float)(tbuf.millitm - msec)/1000;
  81. #endif
  82. #ifdef BSD4v2
  83.     gettimeofday(&tval, &tzone);
  84.     wallclock = tval.tv_sec - then + (float)(tval.tv_usec - usec)/1000000;
  85. #endif
  86.     expected = GRANULE * NUM_ALRM;
  87.     printf("%d x %d sec delays takes %.2f wallclock secs (error %.2f%%)\n",
  88.     NUM_ALRM, GRANULE, wallclock, 100.0*(float)(expected-wallclock)/expected);
  89.     exit(0);
  90. }
  91.  
  92. onalarm() { }
  93.