]> www.ginac.de Git - cln.git/blob - src/timing/cl_t_report.cc
Make @exec_prefix@ usable in shell scripts.
[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 "cl_timing.h"
8
9
10 // Implementation.
11
12 // Round to 3 decimal places.
13 #define CL_HZ 1000
14 #define CL_HZ_NSECS (1000000000/CL_HZ)
15
16 void cl_timing_report (cl_ostream stream, const cl_time_consumption& t)
17 {
18         var uintL real_sec = t.realtime.tv_sec;
19         var uintL real_msec = (t.realtime.tv_nsec + (CL_HZ_NSECS-1)/2) / CL_HZ_NSECS;
20         if (real_msec >= CL_HZ) { real_msec -= CL_HZ; real_sec += 1; }
21         var uintL user_sec = t.usertime.tv_sec;
22         var uintL user_msec = (t.usertime.tv_nsec + (CL_HZ_NSECS-1)/2) / CL_HZ_NSECS;
23         if (user_msec >= CL_HZ) { user_msec -= CL_HZ; user_sec += 1; }
24 #if defined(CL_IO_STDIO)
25         fprintf(stream, "real time: %4u.%03u s, run time: %4u.%03u s",
26                         real_sec, real_msec, user_sec, user_msec);
27 #endif
28 #if defined(CL_IO_IOSTREAM)
29         var char oldfill = stream.fill();
30         var int oldwidth = stream.width();
31         stream << "real time: ";
32         stream.width(4); stream << real_sec; stream << ".";
33         stream.fill('0'); stream.width(3); stream << real_msec;
34         stream.fill(oldfill);
35         stream << " s, ";
36         stream << "run time: ";
37         stream.width(4); stream << user_sec; stream << ".";
38         stream.fill('0'); stream.width(3); stream << user_msec;
39         stream.fill(oldfill);
40         stream << " s";
41         stream.width(oldwidth);
42 #endif
43 }