OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
UtilTiming.hpp
Go to the documentation of this file.
1 
12 #ifndef __TIMING_HEADER__ /*-- allow multiple inclusions --*/
13 #define __TIMING_HEADER__
15 typedef unsigned long long uint64;
16 
17 #include <chrono> // For high-resolution CPU time
18 #include <iomanip>
19 #include <iostream>
20 #include <string> // For output string
21 
22 // Definition of time units
23 const double CLOCK_USE_SEC = 5000;
24 const double CLOCK_USE_MIN = 200000;
25 
32 {
33 
34 private:
35  std::chrono::steady_clock::time_point timeStamp;
36 
37 public:
38 #if defined(_CONSOLE) || defined(_WIN32) || defined(_WIN64)
39  // for Window file system
41  inline void Start() { timeStamp = std::chrono::steady_clock::now(); }
42 
44  inline double Stop() const
45  {
46  auto elapsedTime = std::chrono::steady_clock::now() - timeStamp;
47  return std::chrono::duration<double, std::milli>(elapsedTime).count();
48  }
49 #else
51  __inline__ void Start() { timeStamp = std::chrono::steady_clock::now(); }
52 
54  __inline__ double Stop() const
55  {
56  auto elapsedTime = std::chrono::steady_clock::now() - timeStamp;
57  return std::chrono::duration<double, std::milli>(elapsedTime).count();
58  }
59 #endif
61  void StopInfo(const std::string& info, std::ostream& out = std::cout) const;
62 };
63 
64 #endif /*-- end if for __TIMING_HEADER__ --*/
65 
66 /*----------------------------------------------------------------------------*/
67 /* Brief Change History of This File */
68 /*----------------------------------------------------------------------------*/
69 /* Author Date Actions */
70 /*----------------------------------------------------------------------------*/
71 /* Shizhe Li Oct/01/2021 Create file */
72 /* Chensong Zhang Oct/15/2021 Format file */
73 /* Chensong Zhang Sep/26/2022 Do not use RTC for x86 */
74 /*----------------------------------------------------------------------------*/
const double CLOCK_USE_MIN
Show clock time in minutes.
Definition: UtilTiming.hpp:24
unsigned long long uint64
Unsigned long long int.
Definition: UtilTiming.hpp:15
const double CLOCK_USE_SEC
Show clock time in seconds.
Definition: UtilTiming.hpp:23
Get elapsed wall-time in millisecond.
Definition: UtilTiming.hpp:32
__inline__ double Stop() const
Stop the timer and return duration from start() in ms.
Definition: UtilTiming.hpp:54
__inline__ void Start()
Start the timer.
Definition: UtilTiming.hpp:51
void StopInfo(const std::string &info, std::ostream &out=std::cout) const
Stop the timer and print out duration time.
Definition: UtilTiming.cpp:15