GteTimer.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <LowLevel/GteTimer.h>
10 using namespace gte;
11 
12 #if defined(GTE_NEEDS_64_BIT_CLOCK)
13 
14 #include <cmath>
15 #include <windows.h>
16 
18  :
19  mFrequency(0),
20  mInitialTicks(0),
21  mInvFrequency(0.0)
22 {
23  LARGE_INTEGER frequency = { 1 }, counter = { 0 };
24  QueryPerformanceFrequency(&frequency);
25  QueryPerformanceCounter(&counter);
26  mFrequency = static_cast<int64_t>(frequency.QuadPart);
27  mInitialTicks = static_cast<int64_t>(counter.QuadPart);
28  mInvFrequency = 1.0 / static_cast<double>(mFrequency);
29 }
30 
31 int64_t Timer::GetNanoseconds() const
32 {
33  int64_t ticks = GetTicks();
34  double seconds = mInvFrequency * static_cast<double>(ticks);
35  int64_t nanoseconds = static_cast<int64_t>(ceil(1000000000.0 * seconds));
36  return nanoseconds;
37 }
38 
39 int64_t Timer::GetMicroseconds() const
40 {
41  int64_t ticks = GetTicks();
42  double seconds = mInvFrequency * static_cast<double>(ticks);
43  int64_t microseconds = static_cast<int64_t>(ceil(1000000.0 * seconds));
44  return microseconds;
45 }
46 
47 int64_t Timer::GetMilliseconds() const
48 {
49  int64_t ticks = GetTicks();
50  double seconds = mInvFrequency * static_cast<double>(ticks);
51  int64_t milliseconds = static_cast<int64_t>(ceil(1000.0 * seconds));
52  return milliseconds;
53 }
54 
55 double Timer::GetSeconds() const
56 {
57  int64_t ticks = GetTicks();
58  double seconds = mInvFrequency * static_cast<double>(ticks);
59  return seconds;
60 }
61 
62 void Timer::Reset()
63 {
64  LARGE_INTEGER counter = { 0 };
65  QueryPerformanceCounter(&counter);
66  mInitialTicks = static_cast<int64_t>(counter.QuadPart);
67 }
68 
69 int64_t Timer::GetTicks() const
70 {
71  LARGE_INTEGER counter = { 0 };
72  QueryPerformanceCounter(&counter);
73  return static_cast<int64_t>(counter.QuadPart) - mInitialTicks;
74 }
75 
76 #else
77 
79 {
80  Reset();
81 }
82 
83 int64_t Timer::GetNanoseconds() const
84 {
85  auto currentTime = std::chrono::high_resolution_clock::now();
86  return std::chrono::duration_cast<std::chrono::nanoseconds>(
87  currentTime - mInitialTime).count();
88 }
89 
90 int64_t Timer::GetMicroseconds() const
91 {
92  auto currentTime = std::chrono::high_resolution_clock::now();
93  return std::chrono::duration_cast<std::chrono::microseconds>(
94  currentTime - mInitialTime).count();
95 }
96 
97 int64_t Timer::GetMilliseconds() const
98 {
99  auto currentTime = std::chrono::high_resolution_clock::now();
100  return std::chrono::duration_cast<std::chrono::milliseconds>(
101  currentTime - mInitialTime).count();
102 }
103 
104 double Timer::GetSeconds() const
105 {
106  int64_t msecs = GetMilliseconds();
107  return static_cast<double>(msecs) / 1000.0;
108 }
109 
111 {
112  mInitialTime = std::chrono::high_resolution_clock::now();
113 }
114 
115 #endif
int64_t GetMilliseconds() const
Definition: GteTimer.cpp:97
double GetSeconds() const
Definition: GteTimer.cpp:104
GLuint counter
Definition: glext.h:5361
void Reset()
Definition: GteTimer.cpp:110
GLint GLsizei count
Definition: glcorearb.h:400
int64_t GetMicroseconds() const
Definition: GteTimer.cpp:90
GLfloat seconds
Definition: wglext.h:657
int64_t GetNanoseconds() const
Definition: GteTimer.cpp:83


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01