home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / fweb153.zip / fweb-1.53 / web / time.hweb < prev    next >
Text File  |  1995-09-23  |  2KB  |  77 lines

  1. @z --- time.hweb ---
  2.  
  3. FWEB version 1.53 (September 23, 1995)
  4.  
  5. Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]
  6.  
  7. @x-----------------------------------------------------------------------------
  8.  
  9. @ This file is included into \.{includes.hweb}. It takes care of the
  10. details of cpu and wall clock timing.
  11.  
  12. @<Operating sys...@>=
  13.  
  14. /* --- TIMING --- */
  15.  
  16. /* The compiler-line macro |timing_width| overrides the default format for
  17. the time output; it's the number of \.x's in \.{n.xx} seconds. (See
  18. \.{custom.web}.) */ 
  19. #ifndef TIMING_WIDTH
  20.     #define TIMING_WIDTH 1 // We ensure that it's defined to something.
  21. #endif /* |TIMING_WIDTH| */
  22.  
  23. #include <time.h> /* ANSI: Time-conversion routines. (For non-ANSI
  24.             machines, defines |struct tm|.) */
  25.  
  26. #if TIMING
  27.  
  28. /* We like wall-clock timing more precise than seconds. */
  29.  
  30.  /* \.{Machine-dependent}: Non-ANSI timing: */
  31. #if HAVE_GETTIMEOFDAY
  32.     /* uSec timing */
  33.     #include <sys/time.h>
  34.     #undef NEW_DIFFTIME
  35.     #define NEW_DIFFTIME 1
  36.     #define TIME_T struct timeval
  37.     #ifdef _COMMON_h
  38.         struct timezone tz_dummy;
  39.     #endif
  40.     int gettimeofday PROTO((struct timeval *tp, struct timezone *tzp));
  41.     #define TIME(p) gettimeofday(p, &tz_dummy)
  42. #else
  43. #if HAVE_SYS_TIMEB_H
  44.     /* mSec timing */
  45.     #include <sys/timeb.h>
  46.     #undef NEW_DIFFTIME
  47.     #define NEW_DIFFTIME 1
  48.     #define TIME_T struct timeb 
  49.     #define TIME(p) ftime(p)
  50. #else /* ANSI timing */
  51.     #define TIME_T time_t
  52.     #define TIME(p) time(p)
  53. #endif // |HAVE_SYS_TIMEB_H|
  54. #endif // |HAVE_GETTIMEOFDAY|
  55.  
  56. #if NEW_DIFFTIME
  57.     #define DIFFTIME diff_time /* We supply our own version of
  58. |difftime| when we don't like the ANSI version. See \.{common.web}. (We
  59. can't just call our new version |difftime| because if that's already been
  60. prototyped the compiler will complain about a prototype mismatch.) */
  61. #else
  62.     #define DIFFTIME difftime /* Use the ANSI routine. */
  63. #endif // |NEW_DIFFTIME|
  64.  
  65. clock_t clock PROTO((VOID)); // Not defined on some machines.
  66.  
  67. #ifndef CLOCKS_PER_SEC
  68.     #ifdef CLK_TCK
  69.         #define CLOCKS_PER_SEC CLK_TCK // Some use older name.
  70.     #else
  71.         #define CLOCKS_PER_SEC 1000000 /* Guess at default:
  72. $\mu$sec timing. */ 
  73.     #endif // |CLK_TCK|
  74. #endif // |CLOCKS_PER_SEC|
  75.  
  76. #endif // |TIMING|
  77.