1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:17:45 +00:00

Use 64-bit integers inside Stopwatch to enable longer timings.

This commit is contained in:
Andreas Kling 2019-03-21 13:36:40 +01:00
parent 0114c61cf1
commit 9dfcd95cd7
5 changed files with 155 additions and 25 deletions

View file

@ -5,30 +5,33 @@
#ifdef __cplusplus
struct Stopwatch {
union SplitQword {
struct {
uint32_t lsw;
uint32_t msw;
};
uint64_t qw { 0 };
};
public:
Stopwatch(const char* name)
: m_name(name)
{
read_tsc(&m_start_lsw, &m_start_msw);
read_tsc(&m_start.lsw, &m_start.msw);
}
~Stopwatch()
{
unsigned end_lsw;
unsigned end_msw;
read_tsc(&end_lsw, &end_msw);
if (m_start_msw != end_msw) {
dbgprintf("Stopwatch: differing msw, no result for %s\n", m_name);
}
unsigned diff = end_lsw - m_start_lsw;
dbgprintf("Stopwatch(%s): %u ticks\n", m_name, diff);
SplitQword end;
read_tsc(&end.lsw, &end.msw);
uint64_t diff = end.qw - m_start.qw;
dbgprintf("Stopwatch(%s): %q ticks\n", m_name, diff);
}
private:
const char* m_name { nullptr };
unsigned m_start_lsw { 0 };
unsigned m_start_msw { 0 };
SplitQword m_start;
};
#endif // __cplusplus