QueryPerformanceFrequency的单位

一个简单的问题:

QueryPerformanceFrequency单元是哪个? 赫兹(蜱每秒)?

非常感谢,布鲁诺

Solutions Collecting From Web of "QueryPerformanceFrequency的单位"

问:QueryPerformanceFrequency的单位?

A:KILO-HERTZ(不是Hz)

===========细节====================================== ========

我的研究表明,柜台和Freq都是KILO,KILO-clock-ticks和KILO-HERTZ!

计数器注册KILO点击(KLICKS)和频率是千赫或我悲伤UnderClocked。 当你用Clock_Frequency划分Clock_Ticks时,k 点击/(k点击* sec ^ -1),除了秒外,所有东西都会消失。

这里是一个例子C程序剥离只是要点:

#include "stdio.h" #include <windows.h> // Needed for LARGE_INTEGER // gcc cpu.freq.test.c -o cft.exe // cft.exe -> Sleep d_KLICKS=3417790, d_time=0.999182880 sec, CPU_Freq=3420585 KILO-Hz void main(int argc, char *argv[]) { // Clock KILO-ticks start, end, CPU_Freq in kHz. KILOs cancel LARGE_INTEGER sklick, eklick, cpu_khz; double delta_time; // Expected time in SECONDS. All units above are k. QueryPerformanceFrequency(&cpu_khz); // Gets clock KILO-tics, Klicks/sec QueryPerformanceCounter(&sklick); // Capture cpu Start Klicks Sleep(1000); // Sleep 1000 MILLI-seconds QueryPerformanceCounter(&eklick); // Capture cpu End Klicks delta_time = (eklick.QuadPart-sklick.QuadPart) / (double)cpu_khz.QuadPart; printf("Sleep d_KLICKS=%lld, d_time=%4.9lf sec, CPU_Freq=%lld KILO-Hz\n", eklick.QuadPart-sklick.QuadPart, delta_time, cpu_khz.QuadPart); } 

它实际上编译! 正在运行…

 Sleep d_KLICKS=3418803, d_time=0.999479036 sec, CPU_Freq=3420585 KILO-Hz 

CPU频率读取3420585或3.420585E6或3.4 M-Hertz? < – MEGA-HURTS!OUCH!

实际的CPU频率为3.4兆千赫或3.4千兆赫

微软似乎是困惑(有些事情永远不会改变): https : //msdn.microsoft.com/en-us/library/windows/desktop/dn553408%28v=vs.85%29.aspx

 QueryPerformanceFrequency(&Frequency); QueryPerformanceCounter(&StartingTime); // Activity to be timed QueryPerformanceCounter(&EndingTime); ElapsedMicroseconds.QuadPart = EndingTime.QuadPart - StartingTime.QuadPart; // We now have the elapsed number of ticks, along with the // number of ticks-per-second. 

在1秒内“流逝的滴答”的数量是在百万,而不是十亿,所以他们不是单位CPU时钟,但千分之一时钟滴答声

FREQ相差3个数量级的误差:340万不是“每秒钟滴答”,而是每秒滴答几千个。

只要你们相互分隔,点击就会在几秒钟内取消。 如果一个人如此愚蠢以至于不能在他们的文档中使用ms,并尝试在其他计算中使用他们的“ticks-per-second”,那么结果就是1000或者1 standard_ms_error!

也许我们应该打电话给海因里希检查他的单位? 哎呀! 153年太晚了。 🙁