본문 바로가기
Programming/Server

Making high resolution performance counter

by NoxLuna 2015. 1. 29.

To read the resolution time, you must use the Performance Counter.

 

For GetTickCount () function has the ease of use. Best used when the time measurement is not important. However, the return value of GetTickCount () function ms (mili second) units, but the actual resolution is not a 1ms increments. You can slightly differ.

 

The following is a function of the source to read the current count time is specified by a float using the Performance Counter. Note please use hasyeoseo bosigil.

 

-------------- GxSystem.h -------------------------------------

#ifndef _GX_SYSTEM_H_
#define _GX_SYSTEM_H_
// Initialize timer
void GxInitTimer();
// Get Current time since Initialize timer
float GxGetCurrentTimeInSec();
#endif


 

-------------- GxSystem.cpp -----------------------------------

#include <windows.h>
static LARGE_INTEGER initial;
static LARGE_INTEGER freq;
void GxInitTimer()
{
    QueryPerformanceCounter(&initial);
    QueryPerformanceFrequency(&freq);
}
float GxGetCurrentTimeInSec()
{
    LARGE_INTEGER counter;
    QueryPerformanceCounter(&counter);
    return (float)((long double)(counter.QuadPart - initial.QuadPart)/
        (long double)freq.QuadPart);
}


'Programming > Server' 카테고리의 다른 글

string copy performance test  (0) 2015.01.29

댓글