-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.cpp
41 lines (32 loc) · 812 Bytes
/
Timer.cpp
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
#pragma once
#include "pch.h"
#include "Timer.h"
#include <stdio.h>
TimerFunc::TimerFunc()
{
}
TimerFunc::~TimerFunc()
{
}
void TimerFunc::startTimer()
{
// get ticks per second
QueryPerformanceFrequency(&frequency);
// start timer
QueryPerformanceCounter(&t1);
}
void TimerFunc::stopTimer()
{
// stop timer
QueryPerformanceCounter(&t2);
// compute the elapsed time
elapsedTime = (t2.QuadPart - t1.QuadPart) * 1000.0 / frequency.QuadPart;
int milliseconds = (int)(elapsedTime) % 1000;
int seconds = (int)(elapsedTime / 1000) % 60;
int minutes = (int)(elapsedTime / (1000 * 60)) % 60;
int hours = (int)(elapsedTime / (1000 * 60 * 60)) % 24;
char buffer[50];
sprintf(buffer, "%.2d:%.2d:%.2d.%.3d; \n", hours, minutes, seconds, milliseconds);
OutputDebugStringA(buffer);
elapsedTime = 0;
}