OGS 6.2.2-87-g988ee9c30.dirty.20200123122242
RunTime.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #if defined(USE_MPI)
18 #include <mpi.h>
19 #else
20 #ifndef WIN32
21 #include <sys/time.h>
22 #else
23 #include <windows.h>
24 #endif
25 #endif
26 
27 namespace BaseLib
28 {
29 
31 class RunTime
32 {
33  public:
35  void start()
36  {
37 #if defined(USE_MPI)
38  _start_time = MPI_Wtime();
39 #else
40 #ifndef WIN32
41  timeval t;
42  gettimeofday(&t, nullptr);
43  _start_time = t.tv_sec + t.tv_usec/1000000.0;
44 #else
45  _start_time = timeGetTime();
46 #endif
47 #endif
48  }
49 
51  double elapsed() const
52  {
53 #if defined(USE_MPI)
54  return MPI_Wtime() - _start_time;
55 #else
56 #ifndef WIN32
57  timeval t;
58  gettimeofday(&t, nullptr);
59  return t.tv_sec + t.tv_usec/1000000.0 - _start_time;
60 #else
61  return (timeGetTime() - _start_time)/1000.0;
62 #endif
63 #endif
64  }
65 
66  private:
67  double _start_time = 0.;
68 };
69 
70 } // end namespace BaseLib
double _start_time
Definition: RunTime.h:67
Functionality to build different search length algorithm objects from given config.
Count the running time.
Definition: RunTime.h:31
void start()
Start the timer.
Definition: RunTime.h:35
double elapsed() const
Get the elapsed time after started.
Definition: RunTime.h:51