小编San*_*aga的帖子

如何以微秒精度计算操作时间

我想在Windows平台上以微秒精度计算函数的性能.

现在Windows本身具有毫秒级的粒度,所以我怎样才能做到这一点.

我尝试了以下示例,但没有得到正确的结果.

LARGE_INTEGER ticksPerSecond = {0};
LARGE_INTEGER tick_1 = {0};
LARGE_INTEGER tick_2 = {0};
double uSec = 1000000;

// Get the frequency
QueryPerformanceFrequency(&ticksPerSecond);

//Calculate per uSec freq
double uFreq = ticksPerSecond.QuadPart/uSec;

// Get counter b4 start of op
QueryPerformanceCounter(&tick_1);

// The ope itself
Sleep(10);

// Get counter after opfinished
QueryPerformanceCounter(&tick_2);

// And now the op time in uSec
double diff = (tick_2.QuadPart/uFreq) - (tick_1.QuadPart/uFreq);
Run Code Online (Sandbox Code Playgroud)

c c++ windows precision performance

6
推荐指数
2
解决办法
1293
查看次数

标签 统计

c ×1

c++ ×1

performance ×1

precision ×1

windows ×1