本文介绍了QueryPerformanceFrequency的单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题:

这是QueryPerformanceFrequency的单位?
赫兹(每秒蜱)?

Which is the QueryPerformanceFrequency unit?Hz (ticks per second)?

非常感谢你,
布鲁诺

Thank you very much,Bruno

推荐答案

Q:QueryPerformanceFrequency的单位

Q: Units of QueryPerformanceFrequency?

答:千赫兹(Hz的不)

A: KILO-HERTZ (NOT Hz)

===========详情=================================== ===========

=========== DETAILS ==============================================

我的研究表明,这两个计数器和频率都在多斤,千时钟滴答和千赫!

My research indicates that both Counters and Freq are in KILOs, KILO-clock-ticks and KILO-HERTZ!

计数器注册千点击数(KLICKS)和频率是无论是在kHz或我是可悲的降频。当您Clock_Frequency划分Clock_Ticks,K的点击/(K 的点击* ^秒-1),一切都抹了,除了秒钟。

The counters register KILO-Clicks (KLICKS) and the freq is either in kHz or I am woefully UnderClocked. When you divide the Clock_Ticks by Clock_Frequency, kclicks/(kclicks*sec^-1), everything wipes out except for seconds.

下面是剥离只是要领一个例子C程序:

Here is an example C program stripped to just the essentials:

#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);
}

这实际上编译!正在运行...

It actually compiles! Running...

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

该CPU频率读取3420585或3.420585E6或3.4 M-赫兹? &LT;! - MEGA-HURTS哎唷

The CPU freq reads 3420585 or 3.420585E6 or 3.4 M-Hertz? <- MEGA-HURTS !OUCH!

CPU的实际频率为3.4兆基洛Hz或3.4GHz的

The actual CPU freq is 3.4 Mega-Kilo-Hz or 3.4 GHz

微软似乎混淆(有些东西永远不会改变):

microsoft appears to be confused (some things Never Change):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秒的人数以百万计,也许是数十亿,因此不会UNIT-CPU时钟蜱但基洛CPU时钟蜱

The number of "elapsed ticks" in 1 second is in the MILLIONS, NOT BILLIONS so they are NOT UNIT-CPU-CLOCK-TICKS but KILO-CPU-CLOCK-TICKS

相同的off-by-3的订单数量级的错误FREQ:340万是不是滴答每秒,但千蜱每秒。

Same off-by-3-orders-of-magnitude error for FREQ: 3.4 MILLION is not "ticks-per-second" but THOUSAND-ticks-per-second.

只要你把一个接其他的?点击取消以秒为结果。如果一个人是如此愚蠢的把他们的文档毫秒,并尝试使用在其他一些计算自己的滴答每秒,你会清盘关闭的1000或约1 standard_ms_error一个因素!

As long as you divide one by the other, the ?clicks cancel with a result in seconds. If one were so fatuous as to take ms at their document and try to use their "ticks-per-second" in some other calculation, you would wind up off by a factor of 1000 or ~1 standard_ms_error!

也许我们应该叫海因里希检查他的单位?哎呀! 153年为时已晚。 (

Perhaps we should call Heinrich in to check HIS units? Oops! 153 years too late. :(

这篇关于QueryPerformanceFrequency的单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 02:53