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