Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 08:08:33

0001 // Timing tools.
0002 
0003 #ifndef _CL_TIMING_H
0004 #define _CL_TIMING_H
0005 
0006 #include "cln/config.h"
0007 #include "cln/intparam.h"
0008 #include "cln/types.h"
0009 
0010 #include "cln/io.h"
0011 
0012 namespace cln {
0013 
0014 struct cl_timespec {
0015     uintL tv_sec;   // seconds since 1970-01-01
0016     sintL tv_nsec;  // nanoseconds, >= 0, < 1000000000
0017     // Constructors.
0018     cl_timespec () {}
0019     cl_timespec (uintL sec, sintL nsec)
0020         : tv_sec (sec), tv_nsec (nsec) {}
0021 };
0022 
0023 struct cl_time_duration {
0024     uintL tv_sec;   // seconds
0025     uintL tv_nsec;  // nanoseconds
0026     // Constructors.
0027     cl_time_duration () {}
0028     cl_time_duration (uintL sec)
0029         : tv_sec (sec), tv_nsec (0) {}
0030     cl_time_duration (uintL sec, uintL nsec)
0031         : tv_sec (sec), tv_nsec (nsec) {}
0032 };
0033 
0034 struct cl_time_consumption {
0035     cl_time_duration realtime;  // elapsed time
0036     cl_time_duration usertime;  // system's notion of user time/run time
0037 };
0038 
0039 extern const cl_time_duration operator- (const cl_timespec&, const cl_timespec&);
0040 extern const cl_timespec operator+ (const cl_timespec&, const cl_time_duration&);
0041 extern const cl_timespec operator- (const cl_timespec&, const cl_time_duration&);
0042 extern const cl_time_duration operator+ (const cl_time_duration&, const cl_time_duration&);
0043 extern const cl_time_duration operator- (const cl_time_duration&, const cl_time_duration&);
0044 
0045 extern const cl_timespec cl_current_time ();
0046 extern const cl_time_consumption cl_current_time_consumption ();
0047 
0048 // Report a time consumption.
0049 // (Should better be a virtual member function of `cl_time_consumption').
0050 extern void cl_timing_report (std::ostream&, const cl_time_consumption&);
0051 
0052 struct cl_timing {
0053     // Constructor, starts the time interval.
0054     cl_timing (cl_time_consumption& accumulator);
0055     cl_timing (std::ostream& destination = std::cerr);
0056     cl_timing (const char *, std::ostream& destination = std::cerr);
0057     // Destructor, closes the time interval and does a report.
0058     ~cl_timing ();  
0059 //private:
0060     cl_time_consumption tmp;
0061     void (*report_fn) (const cl_timing&);
0062     void* report_destination;
0063     const char * comment;
0064 };
0065 
0066 // Macro for timing.
0067 // Usage:
0068 //     { CL_TIMING; computation(); }
0069 // or  { CL_TIMING(accumulator); computation(); }
0070 // or  { CL_TIMING(cout); computation(); }
0071 // The timing interval starts immediately and ends at the closing brace.
0072 #define CL_TIMING  CL_TIMING1(__LINE__)
0073 #define CL_TIMING1(line)  CL_TIMING2(line)
0074 #define CL_TIMING2(line)  cl_timing cl_timing_dummy_##line
0075 
0076 }  // namespace cln
0077 
0078 #endif /* _CL_TIMING_H */