nvidia-texture-tools/src/nvcore/Timer.h

61 lines
1.1 KiB
C
Raw Normal View History

2009-07-06 08:57:36 +00:00
// This code is in the public domain -- castano@gmail.com
#ifndef NV_CORE_TIMER_H
#define NV_CORE_TIMER_H
#include <nvcore/nvcore.h>
#if 1
#include <time.h> //clock
class NVCORE_CLASS Timer
{
public:
Timer() {}
void start() { m_start = clock(); }
2009-07-28 08:03:08 +00:00
void stop() { m_stop = clock(); }
2009-07-06 08:57:36 +00:00
int elapsed() const { return (1000 * (m_stop - m_start)) / CLOCKS_PER_SEC; }
private:
clock_t m_start;
2009-07-28 08:03:08 +00:00
clock_t m_stop;
2009-07-06 08:57:36 +00:00
};
#else
#define WINDOWS_LEAN_AND_MEAN
#define VC_EXTRALEAN
#define NOMINMAX
#include <windows.h>
class NVCORE_CLASS Timer
{
public:
Timer() {
2009-07-28 08:03:08 +00:00
// get the tick frequency from the OS
QueryPerformanceFrequency((LARGE_INTEGER*) &m_frequency);
}
2009-07-06 08:57:36 +00:00
void start() { QueryPerformanceCounter((LARGE_INTEGER*) &m_start); }
2009-07-28 08:03:08 +00:00
void stop() { QueryPerformanceCounter((LARGE_INTEGER*) &m_stop); }
2009-07-06 08:57:36 +00:00
int elapsed() const {
2009-07-28 08:03:08 +00:00
return (int)1000 * ((double)m_stop.QuadPart - (double)m_start.QuadPart) / (double)m_frequency.QuadPart;
}
2009-07-06 08:57:36 +00:00
private:
2009-07-28 08:03:08 +00:00
LARGE_INTEGER m_frequency;
LARGE_INTEGER m_start;
LARGE_INTEGER m_stop;
2009-07-06 08:57:36 +00:00
};
#endif // 0
#endif // NV_CORE_TIMER_H