본문 바로가기

System-level프로그래밍

(windows.h) QueryPerformanceFrequency,...

library 쓸때는 방법1: #pragma comment (lib, "kernel32.lib")

아래 두 함수를 시간측정을 위해 사용할 때,
QueryPerformanceFrequency()로 얻은 값은 초당 카운트수,
QueryPerformanceCounter()로 얻은 값은 현재카운트임을 명심하기.
그리고 LAGE_INTEGER 사용시 QuadPart는 64bit 지원 컴파일러에 대해서만 사용하기.
 

출처: MSDN

The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running.

Syntax

BOOL QueryPerformanceFrequency(      
    LARGE_INTEGER *lpFrequency
);

Parameters

lpFrequency
[out] Pointer to a variable that receives the current performance-counter frequency, in counts per second. If the installed hardware does not support a high-resolution performance counter, this parameter can be zero.

Return Value

If the installed hardware supports a high-resolution performance counter, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError. For example, if the installed hardware does not support a high-resolution performance counter, the function fails.



Function Information

Minimum DLL Version kernel32.dll
Header Declared in Winbase.h, include Windows.h
Import library Kernel32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode version.

The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter.

Syntax

BOOL QueryPerformanceCounter(      
    LARGE_INTEGER *lpPerformanceCount
);

Parameters

lpPerformanceCount
[out] Pointer to a variable that receives the current performance-counter value, in counts.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.



Remarks

On a multiprocessor computer, it should not matter which processor is called. However, you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL). To specify processor affinity for a thread, use the SetThreadAffinityMask function.

Function Information

Minimum DLL Version kernel32.dll
Header Declared in Winbase.h, include Windows.h
Import library Kernel32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode version.

LARGE_INTEGER

The LARGE_INTEGER structure is used to represent a 64-bit signed integer value.

Note  Your C compiler may support 64-bit integers natively. For example, Microsoft® Visual C++® supports the __int64 sized integer type. For more information, see the documentation included with your C compiler.

typedef union _LARGE_INTEGER {
  struct {
    DWORD LowPart;
    LONG HighPart;
  };
  struct {
    DWORD LowPart;
    LONG HighPart;
  } u;
  LONGLONG QuadPart;
} LARGE_INTEGER, 
*PLARGE_INTEGER;

Members

LowPart
Low-order 32 bits.
HighPart
High-order 32 bits.
u
LowPart
Low-order 32 bits.
HighPart
High-order 32 bits.
QuadPart
Signed 64-bit integer.

Remarks

The LARGE_INTEGER structure is actually a union. If your compiler has built-in support for 64-bit integers, use the QuadPart member to store the 64-bit integer. Otherwise, use the LowPart and HighPart members to store the 64-bit integer.

Requirements

Client Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header

Declared in Winnt.h; include Windows.h.