]> www.ginac.de Git - cln.git/blob - src/timing/cl_t_report.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / timing / cl_t_report.cc
1 // cl_timing_report().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/timing.h"
8
9
10 // Implementation.
11
12 namespace cln {
13
14 // Round to 3 decimal places.
15 #define CL_HZ 1000
16 #define CL_HZ_NSECS (1000000000/CL_HZ)
17
18 void cl_timing_report (cl_ostream stream, const cl_time_consumption& t)
19 {
20         var uintL real_sec = t.realtime.tv_sec;
21         var uintL real_msec = (t.realtime.tv_nsec + (CL_HZ_NSECS-1)/2) / CL_HZ_NSECS;
22         if (real_msec >= CL_HZ) { real_msec -= CL_HZ; real_sec += 1; }
23         var uintL user_sec = t.usertime.tv_sec;
24         var uintL user_msec = (t.usertime.tv_nsec + (CL_HZ_NSECS-1)/2) / CL_HZ_NSECS;
25         if (user_msec >= CL_HZ) { user_msec -= CL_HZ; user_sec += 1; }
26         var char oldfill = stream.fill();
27         var int oldwidth = stream.width();
28         stream << "real time: ";
29         stream.width(4); stream << real_sec; stream << ".";
30         stream.fill('0'); stream.width(3); stream << real_msec;
31         stream.fill(oldfill);
32         stream << " s, ";
33         stream << "run time: ";
34         stream.width(4); stream << user_sec; stream << ".";
35         stream.fill('0'); stream.width(3); stream << user_msec;
36         stream.fill(oldfill);
37         stream << " s";
38         stream.width(oldwidth);
39 }
40
41 }  // namespace cln