2019-01-28 22:01:47 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
struct Stopwatch {
|
2019-03-21 12:36:40 +00:00
|
|
|
union SplitQword {
|
|
|
|
struct {
|
|
|
|
uint32_t lsw;
|
|
|
|
uint32_t msw;
|
|
|
|
};
|
|
|
|
uint64_t qw { 0 };
|
|
|
|
};
|
2019-05-28 09:53:16 +00:00
|
|
|
|
2019-01-28 22:01:47 +00:00
|
|
|
public:
|
|
|
|
Stopwatch(const char* name)
|
|
|
|
: m_name(name)
|
|
|
|
{
|
2019-03-21 12:36:40 +00:00
|
|
|
read_tsc(&m_start.lsw, &m_start.msw);
|
2019-01-28 22:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Stopwatch()
|
|
|
|
{
|
2019-03-21 12:36:40 +00:00
|
|
|
SplitQword end;
|
|
|
|
read_tsc(&end.lsw, &end.msw);
|
|
|
|
uint64_t diff = end.qw - m_start.qw;
|
2019-03-30 03:20:08 +00:00
|
|
|
dbgprintf("Stopwatch(%s): %Q ticks\n", m_name, diff);
|
2019-01-28 22:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* m_name { nullptr };
|
2019-03-21 12:36:40 +00:00
|
|
|
SplitQword m_start;
|
2019-01-28 22:01:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __cplusplus
|