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