QueryPerformanceCounter 函数 (profileapi.h)

检索性能计数器的当前值,这是可用于时间间隔度量的高分辨率 (<1us) 时间戳。

Syntax

BOOL QueryPerformanceCounter(
  [out] LARGE_INTEGER *lpPerformanceCount
);

参数

[out] lpPerformanceCount

指向接收当前性能计数器值的变量(以计数为单位)的指针。

返回值

如果函数成功,则返回值为非零。

如果函数失败,则返回值为零。 若要获取扩展的错误信息,请调用 GetLastError。 在运行 Windows XP 或更高版本的系统上,当给定的有效参数时,函数将始终成功,因此永远不会返回零。

注解

有关此函数及其用法的详细信息,请参阅 获取高分辨率时间戳

例子

// Gets the current number of ticks from QueryPerformanceCounter. Throws an
// exception if the call to QueryPerformanceCounter fails.
static inline int64_t GetTicks()
{
    LARGE_INTEGER ticks;
    if (!QueryPerformanceCounter(&ticks))
    {
        winrt::throw_last_error();
    }
    return ticks.QuadPart;
}

要求

Requirement 价值
最低支持的客户端 Windows 2000 Professional [桌面应用 |UWP 应用]
支持的最低服务器 Windows 2000 Server [桌面应用 |UWP 应用]
目标平台 Windows操作系统
Header profileapi.h (包括 Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

另请参阅

获取高分辨率时间戳

概念

GetSystemTimePreciseAsFileTime

KeQueryPerformanceCounter

QueryPerformanceFrequency

引用

时间

定时器