home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / byteunix.lzh / byte.1 / clock.c < prev    next >
C/C++ Source or Header  |  1990-05-11  |  2KB  |  111 lines

  1.  
  2.  
  3. /*******************************************************************************
  4.  *  The BYTE UNIX Benchmarks - Release 2
  5.  *          Module: clock.c   SID: 2.4 4/17/90 16:45:32
  6.  *          
  7.  *******************************************************************************
  8.  * Bug reports, patches, comments, suggestions should be sent to:
  9.  *
  10.  *    Ben Smith or Rick Grehan at BYTE Magazine
  11.  *    bensmith@bixpb.UUCP    rick_g@bixpb.UUCP
  12.  *
  13.  *******************************************************************************
  14.  *  Modification Log:
  15.  *  $Header: clock.c,v 5.2 87/12/09 14:42:34 kenj Exp $
  16.  *
  17.  ******************************************************************************/
  18. char SCCSid[] = "@(#) @(#)clock.c:2.4 -- 4/17/90 16:45:32";
  19. /*
  20.  *  clock -- check alarm signal accuracy
  21.  *
  22.  */
  23.  
  24. #include <signal.h>
  25. #include <stdio.h>
  26. #include <sys/types.h>
  27. #ifdef BSD4v1
  28. #include <sys/timeb.h>
  29. #endif
  30. #ifdef BSD4v2
  31. #include <sys/time.h>
  32. #endif
  33. #ifdef SysV
  34. #include <sys/times.h>
  35. #include <sys/param.h>
  36. long    times();
  37. #ifdef interdata
  38. #define HZ tbuffer.tms_cfreq
  39. #endif
  40. #ifndef HZ
  41.     On your system, what is the value of HZ for high resolution elapsed
  42.     time as returned by times() or its equivalent?
  43. #endif
  44. #endif
  45.  
  46. #define GRANULE        5
  47. #define NUM_ALRM    12
  48.  
  49. main(argc, argv)
  50. int    argc;
  51. char    *argv[];
  52. {
  53.     int            onalarm();
  54.     register int    i = 0;
  55.     int            expected;
  56.     float        wallclock;
  57.     long        then;
  58. #ifdef SysV
  59.     struct tms        tbuffer;
  60. #endif
  61. #ifdef BSD4v1
  62.     struct timeb    tbuf;
  63.     int            msec;
  64. #endif
  65. #ifdef BSD4v2
  66.     struct timeval    tval;
  67.     struct timezone    tzone;
  68.     long        usec;
  69. #endif
  70.  
  71. #ifdef SysV
  72.     then = times(&tbuffer);
  73. #else
  74. #ifdef BSD4v1
  75.     ftime(&tbuf);
  76.     then = tbuf.time;
  77.     msec = tbuf.millitm;
  78. #else
  79. #ifdef BSD4v2
  80.     gettimeofday(&tval, &tzone);
  81.     then = tval.tv_sec;
  82.     usec = tval.tv_usec;
  83. #else
  84.     What sort of Unix system is this?
  85. #endif
  86. #endif
  87. #endif
  88.     while (i++ < NUM_ALRM) {
  89.         signal(SIGALRM, onalarm);
  90.         alarm(GRANULE);
  91.         pause();
  92.     }
  93. #ifdef SysV
  94.     wallclock = (times(&tbuffer) - then)/HZ;
  95. #endif
  96. #ifdef BSD4v1
  97.     ftime(&tbuf);
  98.     wallclock = tbuf.time - then + (float)(tbuf.millitm - msec)/1000;
  99. #endif
  100. #ifdef BSD4v2
  101.     gettimeofday(&tval, &tzone);
  102.     wallclock = tval.tv_sec - then + (float)(tval.tv_usec - usec)/1000000;
  103. #endif
  104.     expected = GRANULE * NUM_ALRM;
  105.     printf("%d x %d sec delays takes %.2f wallclock secs (error %.2f%%)\n",
  106.     NUM_ALRM, GRANULE, wallclock, 100.0*(float)(expected-wallclock)/expected);
  107.     exit(0);
  108. }
  109.  
  110. onalarm() { }
  111.