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.

74 lines
2.3 KiB

25 years ago
  1. // Timing tools.
  2. #ifndef _CL_TIMING_H
  3. #define _CL_TIMING_H
  4. #include "cl_config.h"
  5. #include "cl_intparam.h"
  6. #include "cl_types.h"
  7. #include "cl_io.h"
  8. struct cl_timespec {
  9. uintL tv_sec; // seconds since 1970-01-01
  10. sintL tv_nsec; // nanoseconds, >= 0, < 1000000000
  11. // Constructors.
  12. cl_timespec () {}
  13. cl_timespec (uintL sec, sintL nsec)
  14. : tv_sec (sec), tv_nsec (nsec) {}
  15. };
  16. struct cl_time_duration {
  17. uintL tv_sec; // seconds
  18. uintL tv_nsec; // nanoseconds
  19. // Constructors.
  20. cl_time_duration () {}
  21. cl_time_duration (uintL sec)
  22. : tv_sec (sec), tv_nsec (0) {}
  23. cl_time_duration (uintL sec, uintL nsec)
  24. : tv_sec (sec), tv_nsec (nsec) {}
  25. };
  26. struct cl_time_consumption {
  27. cl_time_duration realtime; // elapsed time
  28. cl_time_duration usertime; // system's notion of user time/run time
  29. };
  30. extern const cl_time_duration operator- (const cl_timespec&, const cl_timespec&);
  31. extern const cl_timespec operator+ (const cl_timespec&, const cl_time_duration&);
  32. extern const cl_timespec operator- (const cl_timespec&, const cl_time_duration&);
  33. extern const cl_time_duration operator+ (const cl_time_duration&, const cl_time_duration&);
  34. extern const cl_time_duration operator- (const cl_time_duration&, const cl_time_duration&);
  35. extern const cl_timespec cl_current_time ();
  36. extern const cl_time_consumption cl_current_time_consumption ();
  37. // Report a time consumption.
  38. // (Should better be a virtual member function of `cl_time_consumption').
  39. extern void cl_timing_report (cl_ostream, const cl_time_consumption&);
  40. struct cl_timing {
  41. // Constructor, starts the time interval.
  42. cl_timing (cl_time_consumption& accumulator);
  43. cl_timing (cl_ostream destination = cl_stderr);
  44. cl_timing (const char *, cl_ostream destination = cl_stderr);
  45. // Destructor, closes the time interval and does a report.
  46. ~cl_timing ();
  47. //private:
  48. cl_time_consumption tmp;
  49. void (*report_fn) (const cl_timing&);
  50. void* report_destination;
  51. const char * comment;
  52. };
  53. // Macro for timing.
  54. // Usage:
  55. // { CL_TIMING; computation(); }
  56. // or { CL_TIMING(accumulator); computation(); }
  57. // or { CL_TIMING(cl_stdout); computation(); }
  58. // The timing interval starts immediately and ends at the closing brace.
  59. #define CL_TIMING CL_TIMING1(__LINE__)
  60. #define CL_TIMING1(line) CL_TIMING2(line)
  61. #define CL_TIMING2(line) cl_timing cl_timing_dummy_##line
  62. #endif /* _CL_TIMING_H */