Utilities
Loading...
Searching...
No Matches
timing.h
Go to the documentation of this file.
1//
2// Gundolf Haase, Oct 18 2024
3//
4#pragma once
5#include <chrono> // timing
6#include <stack>
7
8//using Clock = std::chrono::system_clock; //!< The wall clock timer chosen
9using Clock = std::chrono::high_resolution_clock;
10using TPoint= std::chrono::time_point<Clock>;
11
12// [Galowicz, C++17 STL Cookbook, p. 29]
13inline
14std::stack<TPoint> MyStopWatch;
15
24inline auto tic()
25{
26 MyStopWatch.push(Clock::now());
27 return MyStopWatch.top();
28}
29
43inline double toc(TPoint const &t_b = MyStopWatch.top())
44{
45 // https://en.cppreference.com/w/cpp/chrono/treat_as_floating_point
46 using Unit = std::chrono::seconds;
47 using FpSeconds = std::chrono::duration<double, Unit::period>;
48 auto t_e = Clock::now();
49 MyStopWatch.pop();
50 return FpSeconds(t_e-t_b).count();
51}
#define vector
double toc(TPoint const &t_b=MyStopWatch.top())
Definition timing.h:43
auto tic()
Definition timing.h:24
std::chrono::time_point< Clock > TPoint
Definition timing.h:10
std::chrono::high_resolution_clock Clock
Definition timing.h:9
std::stack< TPoint > MyStopWatch
starting time of stopwatch
Definition timing.h:14