Main MRPT website > C++ reference for MRPT 1.9.9
CTicTac.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "system-precomp.h" // Precompiled headers
11 
12 #ifdef _WIN32
13 #include <windows.h>
14 #else
15 #include <sys/time.h>
16 #endif
17 
18 #include <mrpt/core/exceptions.h>
19 #include <mrpt/system/CTicTac.h>
20 #include <cstring>
21 #include <cassert>
22 
23 #include <type_traits>
24 static_assert(
27  "Copy Check");
28 
29 // For Windows: get the common code out of CTicTac so it's only run once!
30 #ifdef _WIN32
32 {
33  static AuxWindowsTicTac& GetInstance() noexcept
34  {
35  static AuxWindowsTicTac obj;
36  return obj;
37  }
38 
39  double dbl_period;
40 
41  private:
42  LARGE_INTEGER m_freq;
43 
44  AuxWindowsTicTac() noexcept : dbl_period(.0)
45  {
46  QueryPerformanceFrequency(&m_freq);
47  assert(m_freq.QuadPart != 0);
48  dbl_period = 1.0 / static_cast<double>(m_freq.QuadPart);
49  }
50 };
51 
52 #endif
53 
54 using namespace mrpt::system;
55 
56 // Macros for easy access to memory with the correct types:
57 #ifdef _WIN32
58 #define LARGE_INTEGER_NUMS reinterpret_cast<LARGE_INTEGER*>(largeInts)
59 #else
60 #define TIMEVAL_NUMS reinterpret_cast<struct timeval*>(largeInts)
61 #endif
62 
63 CTicTac::CTicTac() noexcept
64 {
65  ::memset(largeInts, 0, sizeof(largeInts));
66 
67 #ifdef _WIN32
68  static_assert(
69  sizeof(largeInts) >= 2 * sizeof(LARGE_INTEGER),
70  "sizeof(LARGE_INTEGER) failed!");
71 #else
72  static_assert(
73  sizeof(largeInts) >= 2 * sizeof(struct timeval),
74  "sizeof(struct timeval) failed!");
75 #endif
76  Tic();
77 }
78 
79 void CTicTac::Tic() noexcept
80 {
81 #ifdef _WIN32
82  LARGE_INTEGER* l = LARGE_INTEGER_NUMS;
83  QueryPerformanceCounter(&l[0]);
84 #else
85  struct timeval* ts = TIMEVAL_NUMS;
86  gettimeofday(&ts[0], nullptr);
87 #endif
88 }
89 
90 double CTicTac::Tac() noexcept
91 {
92 #ifdef _WIN32
93  LARGE_INTEGER* l = LARGE_INTEGER_NUMS;
94  QueryPerformanceCounter(&l[1]);
95  return (l[1].QuadPart - l[0].QuadPart) *
97 #else
98  struct timeval* ts = TIMEVAL_NUMS;
99  gettimeofday(&ts[1], nullptr);
100  return (ts[1].tv_sec - ts[0].tv_sec) +
101  1e-6 * (ts[1].tv_usec - ts[0].tv_usec);
102 #endif
103 }
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:25
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
CTicTac() noexcept
Default constructor.
Definition: CTicTac.cpp:63
AuxWindowsTicTac() noexcept
Definition: CTicTac.cpp:44
double dbl_period
Definition: CTicTac.cpp:39
static AuxWindowsTicTac & GetInstance() noexcept
Definition: CTicTac.cpp:33
LARGE_INTEGER m_freq
Definition: CTicTac.cpp:42
GLsizei const GLfloat * value
Definition: glext.h:4117
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
#define LARGE_INTEGER_NUMS
Definition: CTicTac.cpp:58
unsigned long largeInts[4]



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019