HILA
Loading...
Searching...
No Matches
timing.h
1#ifndef TIMING_H
2#define TIMING_H
3
4#include "plumbing/defs.h"
5
6namespace hila {
7
8////////////////////////////////////////////////////////////////
9/// This file defines timer class and other timing related utilities
10
12 double time; // time accumulated in this timer (in sec)
13 int64_t count; // how many times this timer has been used (start - stop interval)
14};
15
16// clang-format off
17////////////////////////////////////////////////////////////////
18///
19/// Timers are used to time recurring events. Usage:
20///
21/// static timer loop_timer("Loop");
22///
23/// loop_timer.start();
24/// < timed section >
25/// loop_timer.stop();
26///
27/// All timer values are automatically reported on program exit (hila::finishrun calls
28/// report_timers())
29///
30/// Timer can be reset with
31/// loop_timer.reset();
32///
33/// Timer value can be inquired with
34/// timer_value tval = loop_timer.value();
35/// where timer_value is a struct defined below.
36///
37///
38/// Other time related functions:
39/// double gettime(); - returns the time in seconds from program
40/// start void timestamp("message"); - prints msg + current date+time +
41/// time from start
42///
43/// void setup_timelimit(long seconds); - sets the cpu time limit (see
44/// time_to_exit())
45/// bool time_to_exit(); - to be called periodically
46/// at a suitable spot in
47/// the program; returns true if the program
48/// should exit now.
49///
50////////////////////////////////////////////////////////////////
51// clang-format on
52
53
54class timer {
55 private:
56 double t_start, t_total;
57 int64_t count; // need more than 32 bits
58 std::string label;
59 bool is_on, is_error;
60
61 public:
62 // initialize timer to this timepoint
63 timer() { init(nullptr); }
64 timer(const char *tag) { init(tag); }
65
66 ~timer() { remove(); }
67
68 void init(const char *tag);
69 void remove();
70 void reset();
71 double start();
72 double stop();
73 void error();
74 void report(bool print_not_timed = false);
75
76 timer_value value();
77};
78
79void report_timers();
80
81//////////////////////////////////////////////////////////////////
82// Prototypes
83//////////////////////////////////////////////////////////////////
84
85double gettime();
86void inittime();
87
88bool time_to_exit();
89void setup_timelimit(long seconds);
90
91void timestamp(const char *msg);
92void timestamp(const std::string &msg);
93
94
95} // namespace hila
96
97#endif /* timing */
This file defines all includes for HILA.
Invert diagonal + const. matrix using Sherman-Morrison formula.
Definition array.h:920
double gettime()
Definition timing.cpp:163
This file defines timer class and other timing related utilities.
Definition timing.h:11