QueryPerformanceFrequency 的单位 [英] Units of QueryPerformanceFrequency

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

问题描述

一个简单的问题:

QueryPerformanceFrequency 单位是什么?Hz(每秒滴答数)?

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

非常感谢,布鲁诺

推荐答案

问:QueryPerformanceFrequency 的单位?

Q: Units of QueryPerformanceFrequency?

A:千赫兹(非赫兹)

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

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

我的研究表明 Counters 和 Freq 都以 KILO、KILO-clock-ticks 和 KILO-HERTZ 为单位!

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

计数器记录了 KILO-Clicks (KLICKS) 并且频率要么以 kHz 为单位,要么我很遗憾地处于 UnderClocked 状态.当您将 Clock_Ticks 除以 Clock_Frequency 时,kclicks/(kclicks*sec^-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-Hertz?<- 超级痛!哎哟!

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

实际 CPU 频率为 3.4 Mega-Kilo-Hz 或 3.4 GHz

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

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

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-CLOCK-TICKS 而是 KILO-CPU-CLOCK-TICKS

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

对于 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.

只要将一个除以另一个,?clicks 就会在几秒钟内取消.如果有人愚蠢到在他们的文档中使用 ms 并尝试在其他一些计算中使用他们的每秒滴答数",那么您最终会以 1000 或 ~1 个标准_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 的单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆