0

循环 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 上报告如此缓慢的值的想法?

4

1 回答 1

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];
}
于 2013-11-20T15:26:04.267 回答