OGS
RunTime.h
Go to the documentation of this file.
1
15#pragma once
16
17#ifdef USE_PETSC
18#include <mpi.h>
19
20#include <limits>
21#else
22#include <chrono>
23#endif
24
25namespace BaseLib
26{
29{
30public:
32 void start()
33 {
34#ifdef USE_PETSC
35 start_time_ = MPI_Wtime();
36#else
37 start_time_ = std::chrono::system_clock::now();
38#endif
39 }
40
42 double elapsed() const
43 {
44#ifdef USE_PETSC
45 return MPI_Wtime() - start_time_;
46#else
47 using namespace std::chrono;
48 return duration<double>(system_clock::now() - start_time_).count();
49#endif
50 }
51
52private:
53#ifdef USE_PETSC
54 double start_time_ = std::numeric_limits<double>::quiet_NaN();
55#else
56 std::chrono::time_point<std::chrono::system_clock> start_time_;
57#endif
58};
59
60} // end namespace BaseLib
Count the running time.
Definition RunTime.h:29
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
double start_time_
Definition RunTime.h:54
void start()
Start the timer.
Definition RunTime.h:32