Simplified testingTimerNsec() on Windows. _div128() would make this super simple, but that's only available on VS2019, and it seems no one has implemented this in software elsewhere (the most I can find are unsigned ones...).
This commit is contained in:
parent
3257710fb7
commit
f948c30a3b
|
@ -50,24 +50,19 @@ void testingTimerEnd(testingTimer *t)
|
||||||
int64_t testingTimerNsec(testingTimer *t)
|
int64_t testingTimerNsec(testingTimer *t)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER qpf;
|
LARGE_INTEGER qpf;
|
||||||
|
int64_t qpnsQuot, qpnsRem;
|
||||||
int64_t c;
|
int64_t c;
|
||||||
int64_t sec;
|
int64_t ret;
|
||||||
int64_t subsec;
|
|
||||||
double subsecf;
|
|
||||||
|
|
||||||
QueryPerformanceFrequency(&qpf);
|
QueryPerformanceFrequency(&qpf);
|
||||||
|
qpnsQuot = testingNsecPerSec / qpf.QuadPart;
|
||||||
|
qpnsRem = testingNsecPerSec % qpf.QuadPart;
|
||||||
c = t->end.QuadPart - t->start.QuadPart;
|
c = t->end.QuadPart - t->start.QuadPart;
|
||||||
|
|
||||||
sec = c / qpf.QuadPart;
|
ret = c * qpnsQuot;
|
||||||
sec *= testingNsecPerSec;
|
// TODO figure out if the following multiplication can overflow
|
||||||
|
ret += (c * qpnsRem) / qpf.QuadPart;
|
||||||
subsec = c % qpf.QuadPart;
|
return ret;
|
||||||
subsecf = (double) subsec;
|
|
||||||
subsecf /= qpf.QuadPart;
|
|
||||||
subsecf *= testingNsecPerSec;
|
|
||||||
subsec = (int64_t) subsecf;
|
|
||||||
|
|
||||||
return sec + subsec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: the idea for the SetThreadContext() nuttery is from https://www.codeproject.com/Articles/71529/Exception-Injection-Throwing-an-Exception-in-Other
|
// note: the idea for the SetThreadContext() nuttery is from https://www.codeproject.com/Articles/71529/Exception-Injection-Throwing-an-Exception-in-Other
|
||||||
|
|
Loading…
Reference in New Issue