LIBINT 2.7.2
timer.h
1/*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_lib_libint_timer_h_
22#define _libint2_src_lib_libint_timer_h_
23
24#ifdef __cplusplus
25
26#include <libint2/util/cxxstd.h>
27
28#if LIBINT2_CPLUSPLUS_STD >= 2011
29
30#include <chrono>
31
32namespace libint2 {
33
37 template <size_t N>
38 class Timers {
39 public:
40 typedef std::chrono::duration<double> dur_t;
41 typedef std::chrono::high_resolution_clock clock_t;
42 typedef std::chrono::time_point<clock_t> time_point_t;
43
44 Timers() {
45 clear();
47 }
48
50 static time_point_t now() {
51 return clock_t::now();
52 }
53
57 void set_now_overhead(size_t ns) {
58 overhead_ = std::chrono::nanoseconds(ns);
59 }
60
62 void start(size_t t) {
63 tstart_[t] = now();
64 }
67 dur_t stop(size_t t) {
68 const auto tstop = now();
69 const dur_t result = (tstop - tstart_[t]) - overhead_;
70 timers_[t] += result;
71 return result;
72 }
74 double read(size_t t) const {
75 return timers_[t].count();
76 }
78 void clear() {
79 for(auto t=0; t!=ntimers; ++t) {
80 timers_[t] = dur_t::zero();
81 tstart_[t] = time_point_t();
82 }
83 }
84
85 private:
86 constexpr static auto ntimers = N;
87 dur_t timers_[ntimers];
88 time_point_t tstart_[ntimers];
89 dur_t overhead_; // the duration of now() call ... use this to automatically adjust reported timings is you need fine-grained timing
90 };
91
92} // namespace libint2
93
94#endif // C++11 or later
95
96#endif // defined(__cplusplus)
97
98#endif // header guard
99
100
Timers aggregates N C++11 "timers"; used to high-resolution profile stages of integral computation.
Definition: timer.h:38
double read(size_t t) const
reads value (in seconds) of timer t , converted to double
Definition: timer.h:74
dur_t stop(size_t t)
stops timer t
Definition: timer.h:67
void clear()
resets timers to zero
Definition: timer.h:78
static time_point_t now()
returns the current time point
Definition: timer.h:50
void set_now_overhead(size_t ns)
use this to report the overhead of now() call; if set, the reported timings will be adjusted for this...
Definition: timer.h:57
void start(size_t t)
starts timer t
Definition: timer.h:62
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24