Mana
Stopwatch.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "Platform.h"
10 
11 #if defined(MANA_TARGET_WINDOWS)
12 #define NOMINMAX
13 #include <windows.h>
14 #elif defined(MANA_TARGET_APPLE)
15 #include <sys/time.h>
16 #else
17 #include <sys/time.h>
18 #endif
19 
20 namespace mana
21 {
22  [[nodiscard]] inline uint64_t GetMicroSecond()
23  {
24 #if defined(MANA_TARGET_WINDOWS)
25  LARGE_INTEGER frequency, counter;
26 
27  if (!QueryPerformanceFrequency(&frequency) || !QueryPerformanceCounter(&counter))
28  return 0;
29 
30  return static_cast<uint64_t>(counter.QuadPart * 1000000 / frequency.QuadPart);
31 #else
32  struct timeval current;
33  return (gettimeofday(&current, nullptr) == 0) ? current.tv_usec : 0;
34 #endif
35  }
36 
37  [[nodiscard]] inline float_t GetSecond()
38  {
39  return static_cast<float_t>(GetMicroSecond()) / static_cast<float_t>(1000000);
40  }
41 }
Definition: CodeBuffer.cpp:12
uint64_t GetMicroSecond()
Definition: Stopwatch.h:22
float_t GetSecond()
Definition: Stopwatch.h:37
float float_t
Definition: Type.h:28