absence_thelab
diff src/common/timing.cpp @ 0:1cffe3409164
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 23 Oct 2014 01:46:07 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/common/timing.cpp Thu Oct 23 01:46:07 2014 +0300 1.3 @@ -0,0 +1,46 @@ 1.4 +#include "timing.h" 1.5 + 1.6 +Timer::Timer() { 1.7 + QueryPerformanceFrequency(&freq); 1.8 + PauseTime.QuadPart = 0; 1.9 + paused = false; 1.10 +} 1.11 + 1.12 +void Timer::Start() { 1.13 + PauseTime.QuadPart = 0; 1.14 + QueryPerformanceCounter(&start); 1.15 +} 1.16 + 1.17 +void Timer::Stop() { 1.18 + QueryPerformanceCounter(&LastStop); 1.19 +} 1.20 + 1.21 +void Timer::Resume() { 1.22 + LARGE_INTEGER resume; 1.23 + 1.24 + QueryPerformanceCounter(&resume); 1.25 + 1.26 + PauseTime.QuadPart += resume.QuadPart - LastStop.QuadPart; 1.27 +} 1.28 + 1.29 + 1.30 +unsigned long Timer::GetTicks() const { 1.31 + LARGE_INTEGER ticks; 1.32 + 1.33 + QueryPerformanceCounter(&ticks); 1.34 + return (unsigned long)(ticks.QuadPart - start.QuadPart - PauseTime.QuadPart); 1.35 +} 1.36 + 1.37 +unsigned long Timer::GetSec() const { 1.38 + LARGE_INTEGER ticks; 1.39 + 1.40 + QueryPerformanceCounter(&ticks); 1.41 + return (unsigned long)((ticks.QuadPart - start.QuadPart - PauseTime.QuadPart)/freq.QuadPart); 1.42 +} 1.43 + 1.44 +unsigned long Timer::GetMilliSec() const { 1.45 + LARGE_INTEGER ticks; 1.46 + 1.47 + QueryPerformanceCounter(&ticks); 1.48 + return (unsigned long)((ticks.QuadPart - start.QuadPart - PauseTime.QuadPart)/(freq.QuadPart/1000)); 1.49 +}