PolyDiM
C++ library for POLYtopal DIscretization Methods
Loading...
Searching...
No Matches
TimeUtilities.hpp
Go to the documentation of this file.
1// _LICENSE_HEADER_
2//
3// Copyright (C) 2019 - 2025.
4// Terms register on the GPL-3.0 license.
5//
6// This file can be redistributed and/or modified under the license terms.
7//
8// See top level LICENSE file for more details.
9//
10// This file can be used citing references in CITATION.cff file.
11
12#ifndef __TimeUtilities_H
13#define __TimeUtilities_H
14
15#include "IOUtilities.hpp"
16#include "chrono"
17
18namespace Gedim
19{
20
21template <class DT = std::chrono::milliseconds, class ClockT = std::chrono::steady_clock> class Timer
22{
23 using timep_t = decltype(ClockT::now());
24
25 timep_t _start = ClockT::now();
26 timep_t _end = {};
27
28 public:
29 void tick()
30 {
31 _end = timep_t{};
32 _start = ClockT::now();
33 }
34
35 void tock()
36 {
37 _end = ClockT::now();
38 }
39
40 template <class duration_t = DT> duration_t duration() const
41 {
42 // Use gsl_Expects if your project supports it.
43 Gedim::Output::Assert(_end != timep_t{} && "Timer must toc before reading the time");
44 return std::chrono::duration_cast<duration_t>(_end - _start);
45 }
46};
47
48} // namespace Gedim
49
50#endif
Eigen column vector.
Definition Eigen_Array.hpp:23
static void Assert(const bool &logicResult)
Assert for all code, generate exception if something goes wrong.
Definition IOUtilities.hpp:126
Definition TimeUtilities.hpp:22
void tock()
Definition TimeUtilities.hpp:35
duration_t duration() const
Definition TimeUtilities.hpp:40
void tick()
Definition TimeUtilities.hpp:29
Definition Eigen_Array.cpp:22