You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.5 KiB

  1. /* LINTLIBRARY */
  2. #include <stdio.h>
  3. #include "util.h"
  4. #ifdef IBM_WATC /* IBM Waterloo-C compiler (same as bsd 4.2) */
  5. #define void int
  6. #define BSD
  7. #endif
  8. #ifdef BSD
  9. #include <sys/types.h>
  10. #include <sys/time.h>
  11. #include <sys/resource.h>
  12. #endif
  13. #if defined(UNIX60) || defined(UNIX100) || defined(__CYGWIN32__)
  14. #include <sys/types.h>
  15. #include <sys/times.h>
  16. #endif
  17. #ifdef vms /* VAX/C compiler -- times() with 100 HZ clock */
  18. #include <types.h>
  19. #include <time.h>
  20. #endif
  21. /*
  22. * util_cpu_time -- return a long which represents the elapsed processor
  23. * time in milliseconds since some constant reference
  24. */
  25. long
  26. util_cpu_time()
  27. {
  28. long t = 0;
  29. #ifdef BSD
  30. struct rusage rusage;
  31. (void) getrusage(RUSAGE_SELF, &rusage);
  32. t = (long) rusage.ru_utime.tv_sec*1000 + rusage.ru_utime.tv_usec/1000;
  33. #endif
  34. #ifdef IBMPC
  35. long ltime;
  36. (void) time(&ltime);
  37. t = ltime * 1000;
  38. #endif
  39. #ifdef UNIX60 /* times() with 60 Hz resolution */
  40. struct tms buffer;
  41. times(&buffer);
  42. t = buffer.tms_utime * 16.6667;
  43. #endif
  44. #ifdef UNIX100
  45. struct tms buffer; /* times() with 100 Hz resolution */
  46. times(&buffer);
  47. t = buffer.tms_utime * 10;
  48. #endif
  49. #ifdef __CYGWIN32__
  50. /* Works under Windows NT but not Windows 95. */
  51. struct tms buffer; /* times() with 1000 Hz resolution */
  52. times(&buffer);
  53. t = buffer.tms_utime;
  54. #endif
  55. #ifdef vms
  56. tbuffer_t buffer; /* times() with 100 Hz resolution */
  57. times(&buffer);
  58. t = buffer.proc_user_time * 10;
  59. #endif
  60. return t;
  61. }