Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
TicToc.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Sandals project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * e-mail: davide.stocco@unitn.it e-mail: enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef SANDALS_TIC_TOC_HH
14#define SANDALS_TIC_TOC_HH
15
16#include <Sandals.hh>
17
18namespace Sandals {
19
20 /*\
21 | _____ _ _____
22 | |_ _(_) __|_ _|__ ___
23 | | | | |/ __|| |/ _ \ / __|
24 | | | | | (__ | | (_) | (__
25 | |_| |_|\___||_|\___/ \___|
26 |
27 \*/
28
35 template <typename Real>
36 class TicToc {
37
38 using Clock = std::chrono::high_resolution_clock;
39 using Time = std::chrono::microseconds;
40
41 Clock::time_point m_start_time;
42 Clock::time_point m_stop_time;
44
45 public:
49 TicToc(const TicToc &) = delete;
50
54 TicToc & operator=(TicToc const &) = delete;
55
60
64 void tic() {this->m_start_time = Clock::now();}
65
69 void toc()
70 {
71 this->m_stop_time = Clock::now();
72 this->m_elapsed_time = std::chrono::duration_cast<Time>(
73 this->m_stop_time - this->m_start_time
74 );
75 }
76
81 Real elapsed_s() const {return Real(1.0e-6)*this->m_elapsed_time.count();}
82
87 Real elapsed_ms() const {return Real(1.0e-3)*this->m_elapsed_time.count();}
88
93 Real elapsed_us() const {return this->m_elapsed_time.count();}
94
95 }; // class TicToc
96
97} // namespace Sandals
98
99#endif // SANDALS_TIC_TOC_HH
Time m_elapsed_time
Definition TicToc.hh:43
Real elapsed_us() const
Definition TicToc.hh:93
TicToc(const TicToc &)=delete
Clock::time_point m_start_time
Definition TicToc.hh:41
TicToc()
Definition TicToc.hh:59
void toc()
Definition TicToc.hh:69
TicToc & operator=(TicToc const &)=delete
Real elapsed_ms() const
Definition TicToc.hh:87
std::chrono::high_resolution_clock Clock
Definition TicToc.hh:38
Real elapsed_s() const
Definition TicToc.hh:81
std::chrono::microseconds Time
Definition TicToc.hh:39
Clock::time_point m_stop_time
Definition TicToc.hh:42
void tic()
Definition TicToc.hh:64
The namespace for the Sandals library.
Definition Sandals.hh:89