etime_.c 830 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "time.h"
  2. #ifdef MSDOS
  3. #undef USE_CLOCK
  4. #define USE_CLOCK
  5. #endif
  6. #ifndef REAL
  7. #define REAL double
  8. #endif
  9. #ifndef USE_CLOCK
  10. #define _INCLUDE_POSIX_SOURCE /* for HP-UX */
  11. #define _INCLUDE_XOPEN_SOURCE /* for HP-UX */
  12. #include "ctype.h"
  13. #include "time.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #endif
  18. #undef Hz
  19. #ifdef CLK_TCK
  20. #define Hz CLK_TCK
  21. #else
  22. #ifdef HZ
  23. #define Hz HZ
  24. #else
  25. #define Hz 60
  26. #endif
  27. #endif
  28. REAL
  29. #ifdef KR_headers
  30. etime_(tarray) float *tarray;
  31. #else
  32. etime_(float *tarray)
  33. #endif
  34. {
  35. #ifdef USE_CLOCK
  36. #ifndef CLOCKS_PER_SECOND
  37. #define CLOCKS_PER_SECOND Hz
  38. #endif
  39. double t = clock();
  40. tarray[1] = 0;
  41. return tarray[0] = t / CLOCKS_PER_SECOND;
  42. #else
  43. struct tms t;
  44. times(&t);
  45. return (tarray[0] = (double)t.tms_utime/Hz)
  46. + (tarray[1] = (double)t.tms_stime/Hz);
  47. #endif
  48. }
  49. #ifdef __cplusplus
  50. }
  51. #endif