Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
TicToc.hxx
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_HXX
14#define SANDALS_TIC_TOC_HXX
15
16namespace Sandals {
17
18 /*\
19 | _____ _ _____
20 | |_ _(_) __|_ _|__ ___
21 | | | | |/ __|| |/ _ \ / __|
22 | | | | | (__ | | (_) | (__
23 | |_| |_|\___||_|\___/ \___|
24 |
25 \*/
26
33 class TicToc {
34
35 using Clock = std::chrono::high_resolution_clock;
36 using Time = std::chrono::microseconds;
37
38 Clock::time_point m_start_time;
39 Clock::time_point m_stop_time;
41
42 public:
43
47 TicToc(const TicToc &) = delete;
48
52 TicToc & operator=(TicToc const &) = delete;
53
58
62 void tic() {this->m_start_time = Clock::now();}
63
67 void toc()
68 {
69 this->m_stop_time = Clock::now();
70 this->m_elapsed_time = std::chrono::duration_cast<Time>(
71 this->m_stop_time - this->m_start_time
72 );
73 }
74
79 Real elapsed_s() const {return Real(1.0e-6)*this->m_elapsed_time.count();}
80
85 Real elapsed_ms() const {return Real(1.0e-3)*this->m_elapsed_time.count();}
86
91 Real elapsed_us() const {return this->m_elapsed_time.count();}
92
93 }; // class TicToc
94
95} // namespace Sandals
96
97#endif // SANDALS_TIC_TOC_HXX
void tic()
Definition TicToc.hxx:62
Real elapsed_ms() const
Definition TicToc.hxx:85
Clock::time_point m_start_time
Definition TicToc.hxx:38
Real elapsed_s() const
Definition TicToc.hxx:79
Real elapsed_us() const
Definition TicToc.hxx:91
TicToc & operator=(TicToc const &)=delete
TicToc(const TicToc &)=delete
TicToc()
Definition TicToc.hxx:57
Time m_elapsed_time
Definition TicToc.hxx:40
std::chrono::microseconds Time
Definition TicToc.hxx:36
std::chrono::high_resolution_clock Clock
Definition TicToc.hxx:35
Clock::time_point m_stop_time
Definition TicToc.hxx:39
void toc()
Definition TicToc.hxx:67
The namespace for the Sandals library.
Definition Sandals.hh:73
double Real
Definition Sandals.hh:84