dtime_.c 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "sys/types.h"
  13. #include "sys/times.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. dtime_(tarray) float *tarray;
  31. #else
  32. dtime_(float *tarray)
  33. #endif
  34. {
  35. #ifdef USE_CLOCK
  36. #ifndef CLOCKS_PER_SECOND
  37. #define CLOCKS_PER_SECOND Hz
  38. #endif
  39. static double t0;
  40. double t = clock();
  41. tarray[1] = 0;
  42. tarray[0] = (t - t0) / CLOCKS_PER_SECOND;
  43. t0 = t;
  44. return tarray[0];
  45. #else
  46. struct tms t;
  47. static struct tms t0;
  48. times(&t);
  49. tarray[0] = (double)(t.tms_utime - t0.tms_utime) / Hz;
  50. tarray[1] = (double)(t.tms_stime - t0.tms_stime) / Hz;
  51. t0 = t;
  52. return tarray[0] + tarray[1];
  53. #endif
  54. }
  55. #ifdef __cplusplus
  56. }
  57. #endif