Repository navigation
Expand file tree
/
Copy pathTimer.cpp
More file actions
77 lines (53 loc) · 1.61 KB
/
Copy pathTimer.cpp
File metadata and controls
77 lines (53 loc) · 1.61 KB
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
// SPDX-FileCopyrightText: Copyright (c) 2026 Martin Mittring
// SPDX-License-Identifier: Apache-2.0
#include "global.h"
#include "Timer.h"
#include <windows.h>
CTimer g_Timer;
CTimer::CTimer()
{
QueryPerformanceFrequency((LARGE_INTEGER*)&m_PerformanceFrequency);
}
double CTimer::GetAbsoluteTime() const
{
ASSERT(m_PerformanceFrequency);
LARGE_INTEGER b;
QueryPerformanceCounter(&b);
return (double)(b.QuadPart) / (double)m_PerformanceFrequency;
}
CScopedCPUTimer::~CScopedCPUTimer()
{
double EndTime = g_Timer.GetAbsoluteTime();
float TimeDelta = (float)(EndTime - StartTime);
/* hidden for now
char str[1024];
sprintf_s(str, sizeof(str), "CPU %*.1f ms %s", 6, TimeDelta * 1000, Text); // 6 spaces (see trick here: http://www.cplusplus.com/reference/cstdio/printf/)
g_Renderer.textContext.Print(20, g_Renderer.textContext.CursorY, str);
const int yStep = 11;
g_Renderer.textContext.CursorY += yStep;
*/
/*
if (!Name.empty())
{
OutputDebugStringA(": ");
OutputDebugStringW(Name.c_str());
}
OutputDebugStringA("\n");
*/
}
CScopedCPUTimerLog::~CScopedCPUTimerLog()
{
double EndTime = g_Timer.GetAbsoluteTime();
float TimeDelta = (float)(EndTime - StartTime);
char str[1024];
sprintf_s(str, sizeof(str) / sizeof(str[0]), " %*.1f ms ", 6, TimeDelta * 1000); // 6 spaces (see trick here: http://www.cplusplus.com/reference/cstdio/printf/)
OutputDebugStringA(str);
sprintf_s(str, sizeof(str) / sizeof(str[0]), " SCOPED_CPU_TIMER_LOG %s", Text);
OutputDebugStringA(str);
if (!Name.empty())
{
OutputDebugStringA(": ");
OutputDebugStringW(Name.c_str());
}
OutputDebugStringA("\n");
}