blob: ad3bb1c32cbb25f27f73f27fbbb3ee27a4e78565 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* Copyright 2010-2017 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#include "bx_p.h"
#include <bx/timer.h>
#if BX_PLATFORM_ANDROID
# include <time.h> // clock, clock_gettime
#elif BX_PLATFORM_EMSCRIPTEN
# include <emscripten.h>
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
# include <windows.h>
#else
# include <sys/time.h> // gettimeofday
#endif // BX_PLATFORM_
namespace bx
{
int64_t getHPCounter()
{
#if BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_XBOXONE \
|| BX_PLATFORM_WINRT
LARGE_INTEGER li;
// Performance counter value may unexpectedly leap forward
// http://support.microsoft.com/kb/274323
QueryPerformanceCounter(&li);
int64_t i64 = li.QuadPart;
#elif BX_PLATFORM_ANDROID
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
int64_t i64 = now.tv_sec*INT64_C(1000000000) + now.tv_nsec;
#elif BX_PLATFORM_EMSCRIPTEN
int64_t i64 = int64_t(1000.0f * emscripten_get_now() );
#elif !BX_PLATFORM_NONE
struct timeval now;
gettimeofday(&now, 0);
int64_t i64 = now.tv_sec*INT64_C(1000000) + now.tv_usec;
#else
BX_CHECK(false, "Not implemented!");
int64_t i64 = UINT64_MAX;
#endif // BX_PLATFORM_
return i64;
}
int64_t getHPFrequency()
{
#if BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_XBOXONE \
|| BX_PLATFORM_WINRT
LARGE_INTEGER li;
QueryPerformanceFrequency(&li);
return li.QuadPart;
#elif BX_PLATFORM_ANDROID
return INT64_C(1000000000);
#elif BX_PLATFORM_EMSCRIPTEN
return INT64_C(1000000);
#else
return INT64_C(1000000);
#endif // BX_PLATFORM_
}
} // namespace bx
|