#include <windows.h>
#include <stdio.h>
#include <stdint.h>
// assuming we return times with microsecond resolution
#define STOPWATCH_TICKS_PER_US 1
uint64_t GetStopWatch()
{
LARGE_INTEGER t, freq;
uint64_t val;
QueryPerformanceCounter(&t);
QueryPerformanceFrequency(&freq);
return (uint64_t) (t.QuadPart / (double) freq.QuadPart * 1000000);
}
void task()
{
printf("hi\n");
}
int main()
{
uint64_t start = GetStopWatch();
task();
uint64_t stop = GetStopWatch();
printf("Elapsed time (microseconds): %lld\n", stop - start);
}
以上包含查询性能计数器函数检索高分辨率性能计数器的当前值和查询性能频率函数检索高分辨率性能计数器的频率。如果我正在调用任务();函数多次,然后开始和停止时间之间的差异会有所不同,但我应该得到相同的时间差来多次调用任务函数。谁能帮我找出上面代码中的错误?