-
Notifications
You must be signed in to change notification settings - Fork 2
/
djl_perf.hxx
83 lines (65 loc) · 2.24 KB
/
djl_perf.hxx
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
class CPerfTime
{
private:
LARGE_INTEGER liLastCall;
LARGE_INTEGER liFrequency;
NUMBERFMT NumberFormat;
WCHAR awcRender[ 100 ];
public:
CPerfTime()
{
ZeroMemory( &NumberFormat, sizeof NumberFormat );
NumberFormat.NumDigits = 0;
NumberFormat.Grouping = 3;
NumberFormat.lpDecimalSep = (LPWSTR) L".";
NumberFormat.lpThousandSep = (LPWSTR) L",";
Baseline();
QueryPerformanceFrequency( &liFrequency );
}
void Baseline()
{
QueryPerformanceCounter( &liLastCall );
}
int RenderLL( LONGLONG ll, WCHAR * pwcBuf, ULONG cwcBuf )
{
WCHAR awc[100];
swprintf( awc, L"%I64u", ll );
if ( 0 != cwcBuf )
*pwcBuf = 0;
return GetNumberFormat( LOCALE_USER_DEFAULT, 0, awc, &NumberFormat, pwcBuf, cwcBuf );
} //RenderLL
WCHAR * RenderLL( LONGLONG ll )
{
WCHAR awc[100];
swprintf( awc, L"%I64u", ll );
awcRender[0] = 0;
GetNumberFormat( LOCALE_USER_DEFAULT, 0, awc, &NumberFormat, awcRender, sizeof awcRender / sizeof WCHAR );
return awcRender;
} //RenderLL
void CumulateSince( LONGLONG & running )
{
LARGE_INTEGER liNow;
QueryPerformanceCounter( &liNow );
LONGLONG since = liNow.QuadPart - liLastCall.QuadPart;
liLastCall = liNow;
InterlockedExchangeAdd64( &running, since );
}
LONGLONG TimeNow()
{
LARGE_INTEGER liNow;
QueryPerformanceCounter( &liNow );
return liNow.QuadPart;
}
LONGLONG DurationToMS( LONGLONG duration )
{
duration *= 1000000;
return ( duration / liFrequency.QuadPart ) / 1000;
}
WCHAR * RenderDurationInMS( LONGLONG duration )
{
LONGLONG x = DurationToMS( duration );
RenderLL( x, awcRender, sizeof awcRender / sizeof WCHAR );
return awcRender;
}
}; //CPerfTime