我想实现一个GetTime帮助函数。它获取当前时间(以计数为单位),然后获取系统每秒的计数数量,因此您可以通过它的关系以秒为单位获取当前时间。这些时间计数器细化语句的目的是什么?
但之后,有一些改进代码,我真的不明白。为什么最后两个陈述在那里?
double GetTime()
{
// Current time value, measured in counts
__int64 timeInCounts;
QueryPerformanceCounter((LARGE_INTEGER *)(&timeInCounts));
// To get the frequency (counts per second) of the performance timer
__int64 countsPerSecond;
QueryPerformanceFrequency((LARGE_INTEGER *)(&countsPerSecond));
double r, r0, r1;
// Get the time in seconds with the following relation
r0 = double (timeInCounts/countsPerSecond);
// There is some kind of acuracy improvement here
r1 = (timeInCounts - ((timeInCounts/countsPerSecond)*countsPerSecond))
/(double)(countsPerSecond);
r = r0 + r1;
return r;
}
嗨,r0只是几秒钟的时间,但r1应该始终为0,如果你简化它的公式,但它不是。这就是为什么我不知道它是什么计算,为什么它必须在那里。我想它必须有一些准确的改进,但我不能说它在做什么。 – Shomismo
如果你检查'r1'的值,我想你会发现它的值大于零且小于1。请注意'countsPerSecond'被转换为'double',所以'r1'不是整数除法的结果。 –
那就对了。你这样做是否会得到更加敏锐的结果?它是否比r0计算更精确(它也被称为doble)? – Shomismo