循环访问QueryPerformanceCounter()并保存值:
// Main loop for timer test
for ( int i = 0; i < ITERATIONS; i++ ) // ITERATIONS = 1000
{
QueryPerformanceCounter(&li);
time[i] = double(li.QuadPart) / PCFreq; //1,193,182 per second
}
//calculate the difference between each call
// and save in difference[]
for ( int j = 0; j < (ITERATIONS - 1) ; j++ )
{
difference[j] = time[j+1] - time[j];
}
(除以PCFreq给出每次通话之间的时间。)
高分辨率计时器/计数器应该正常工作,因为它没有返回默认频率1000.
每个时间戳之间的平均值为11.990884微秒(一千个时间戳记)。
这似乎非常缓慢。
这个测试有缺陷吗?
或者为什么在1.1Ghz Celeron上报告这么慢的值?
答案 0 :(得分:2)
在第一个循环中消除浮点数学可能是值得的,以便不考虑Win 7 Desktop和Embedded Compact 7之间的(潜在)差异。所以,像:
LARGE_INTEGER counter[ITERATIONS];
// Main loop for timer test
for ( int i = 0; i < ITERATIONS; i++ ) // ITERATIONS = 1000
{
QueryPerformanceCounter(&counter[i]);
}
time[0] = double(counter[0].QuadPart) / PCFreq; //1,193,182 per second
//calculate the difference between each call
// and save in difference[]
for ( int j = 0; j < (ITERATIONS - 1) ; j++ )
{
time[j+1] = double(counter[j+1].QuadPart) / PCFreq; //1,193,182 per second
difference[j] = time[j+1] - time[j];
}