QueryPerformanceCounter的多次使用?
我学习线程大约3周。我现在有一个练习,用C生成3个线程,并测量线程在ns中创建和启动的时间。显然,我使用QueryPerformanceCounter进行测量QueryPerformanceCounter的多次使用?,c,multithreading,performance,time,performancecounter,C,Multithreading,Performance,Time,Performancecounter,我学习线程大约3周。我现在有一个练习,用C生成3个线程,并测量线程在ns中创建和启动的时间。显然,我使用QueryPerformanceCounter进行测量 ... __int64 Time_Create, Time_Start, freq, start, start2,create, end; //Time_Create to measure when the thread created. //Time_Start to measure the time start. ... Q
...
__int64 Time_Create, Time_Start, freq, start, start2,create, end;
//Time_Create to measure when the thread created.
//Time_Start to measure the time start.
...
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
QueryPerformanceCounter(&start2);
...
for (int i = 0; i<3; i++)
{...
QueryPerformanceCounter(&create);
//Creating threads
hArray_Of_Thread_Handle[i] = CreateThread(
...
QueryPerformanceCounter(&end);
Time_Create = ((create - start) * 1000000) / freq;
Time_Start = ((end - start2) * 1000000) / freq;
printf("Thread %d created at TC %d ns and started at TS %d ns \n" , i+1 , Time_Create, Time_Start);
}
....
我的开始时间总是0,这是错误的。
所以我想知道是否可以使用多个QueryPerformanceCounter?还是我误解了这个练习?还是我用错了方法
谢谢你的阅读和帮助
编辑:
回答:将%d更改为%I64d,以便可以打印u int64。@DavidSchwartz抱歉
Time\u End
实际上是Time\u Start
。当我把代码带到这里时,我担心为开始时间命名Time\u End
会混淆其他名称。在我的代码中,所有的Time\u Start
都是Time\u End
。我刚刚编辑了代码。您不能用%d
打印\uu int64
,这是int
的格式说明符。谢谢。我尝试了%I64d
,效果很好。非常感谢你的时间。有些输出显示为%d
,这仍然很奇怪。
Thread 1 created at TC 3 ns and started at TS 0 ns.
Thread 2 created at TC 1145 ns and started at TS 0 ns.
Thread 3 created at TC 1190 ns and started at TS 0 ns.