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.

78 lines
2.3 KiB

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