M2_SETI/A4/TP_GPU-master/TP2_reduction/windows/CpuTimer.h

38 lines
651 B
C
Raw Normal View History

2022-12-09 09:03:22 +01:00
#pragma once
#include <windows.h>
struct CpuTimer
{
void Start()
{
QueryPerformanceCounter(&m_start);
}
void Stop()
{
QueryPerformanceCounter(&m_stop);
}
// Returns elapsed time in milliseconds (ms)
double Elapsed()
{
return (m_stop.QuadPart - m_start.QuadPart - m_overhead) * 1000.0 / m_freq.QuadPart;
}
private:
// Returns the overhead of the timer in ticks
static LONGLONG GetOverhead()
{
CpuTimer t;
t.Start();
t.Stop();
return t.m_stop.QuadPart - t.m_start.QuadPart;
}
LARGE_INTEGER m_start;
LARGE_INTEGER m_stop;
static LARGE_INTEGER m_freq;
static LONGLONG m_overhead;
};