本文整理汇总了C++中QueryPerformanceFrequency函数的典型用法代码示例。如果您正苦于以下问题:C++ QueryPerformanceFrequency函数的具体用法?C++ QueryPerformanceFrequency怎么用?C++ QueryPerformanceFrequency使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QueryPerformanceFrequency函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QueryPerformanceFrequency
StopWatch::StopWatch()
{
timer.start.QuadPart = 0;
timer.stop.QuadPart = 0;
QueryPerformanceFrequency(&frequency);
}
示例2: InitCPUTicks
void InitCPUTicks()
{
QueryPerformanceFrequency( &lfreq );
}
示例3: SetIcon
BOOL CSoundDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
ant_k_freq = _k_freq = 1;
m_freq.SetRange(0,100);
m_freq.SetPos(100-_k_freq*50);
_volumen = 1;
_left = 0.5;
_right = 0.5;
m_vol.SetRange(0,100);
m_vol.SetPos((1-_volumen)*100);
m_left.SetRange(0,100);
m_left.SetPos((1-_left)*100);
m_right.SetRange(0,100);
m_right.SetPos((1-_right)*100);
// Cargo el wav que voy a usar de muestreo
char wav = QUE_WAV;
switch(wav)
{
case 0:
_cant_samples = generateWav("jet.wav",&_pcm);
break;
case 1:
_cant_samples = generateWav("engine1.wav",&_pcm);
break;
case 2:
_cant_samples = generateWav("spaceship.wav",&_pcm)*0.5;
break;
}
_index = 0;
WAVEFORMATEX Format;
Format.cbSize = sizeof(WAVEFORMATEX);
Format.wFormatTag = WAVE_FORMAT_PCM;
Format.nChannels = 2;
Format.nSamplesPerSec = SAMPLE_RATE;
Format.wBitsPerSample = 16;
Format.nBlockAlign = 4;
Format.nAvgBytesPerSec = Format.nSamplesPerSec*Format.nBlockAlign;
if(waveOutOpen(&hWaveOut, WAVE_MAPPER, &Format, (DWORD)GetSafeHwnd() ,
0L,CALLBACK_WINDOW)!=MMSYSERR_NOERROR)
{
return TRUE;
}
QueryPerformanceFrequency(&F);
QueryPerformanceCounter(&T0);
// Genereo el timer
SetTimer(999,lap=TIME_LAP,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
示例4: TEST_SPEED_FILE_IO
void TEST_SPEED_FILE_IO()
{
LARGE_INTEGER freq, perf_start, perf_end;
float freqms;
QueryPerformanceFrequency(&freq);
freqms = freq.QuadPart / 1000.0f;
std::cout << "Testing file read" << '\n';
float arr1[10267 * 3];
float arr2[10267 * 3];
float arr3[10267 * 3];
// C style
QueryPerformanceCounter(&perf_start);
FILE* fr = fopen("test.bufa", "r");
for (int i = 0; i < 10267 * 3; i++)
{
float temp;
fscanf(fr, "%f", &temp);
arr1[i] = temp;
}
QueryPerformanceCounter(&perf_end);
float elapsedC = (perf_end.QuadPart - perf_start.QuadPart) / freqms;
std::cout << "C style read\n";
std::cout << "Total duration = " << elapsedC << "ms\n";
fclose(fr);
// C buffer style
QueryPerformanceCounter(&perf_start);
fr = fopen("test.bufa", "r");
fseek(fr, 0, SEEK_END);
long lSize = ftell(fr);
rewind(fr);
char* buffer = (char*)malloc(sizeof(char)*lSize);
fread(buffer, 1, lSize, fr);
std::stringstream ss(buffer);
for (int i = 0; i < 10267 * 3; i++)
{
float temp;
ss >> temp;
arr2[i] = temp;
}
QueryPerformanceCounter(&perf_end);
float elapsedCbuf = (perf_end.QuadPart - perf_start.QuadPart) / freqms;
std::cout << "C buffer with stringstream style read\n";
std::cout << "Total duration = " << elapsedCbuf << "ms\n";
fclose(fr);
// C++ style
std::ifstream f;
const int N = sizeof(float) * 10267 * 3;
char buff[N];
f.rdbuf()->pubsetbuf(buff, N);
f.open("test.bufa", std::ios::in | std::ios::binary);
QueryPerformanceCounter(&perf_start);
for (int i = 0; i < 10267 * 3; i++)
{
float temp;
f >> temp;
arr3[i] = temp;
}
QueryPerformanceCounter(&perf_end);
float elapsedCpp = (perf_end.QuadPart - perf_start.QuadPart) / freqms;
std::cout << "C++ style read\n";
std::cout << "Total duration = " << elapsedCpp << "ms\n";
f.close();
}
示例5: PVRFrameEnableControlWindow
//程序运行
int CCApplication::run()
{
//设置注册表PVRFrame隐藏
PVRFrameEnableControlWindow(false);
//主消息循环
MSG msg;
LARGE_INTEGER nFreq;
LARGE_INTEGER nLast;
LARGE_INTEGER nNow;
//WINDOWS高精度定时器的用法,先获取频率
QueryPerformanceFrequency(&nFreq);
//获取当前的计数值,即频率x当前时间
QueryPerformanceCounter(&nLast);
//initInstance函数为虚函数,由派生类AppDelegate进行了重载。此段代码在调用AppDelegate重载的initInstance函数之后调用applicationDidFinishLaunching函数完成一些初始化处理。
//注:AppDelegate重载initInstance函数做了什么我们暂且只先认为它如平时我们WINDOWS基本框架程序一样创建了一个Windows窗口。【伏笔1后面会有讲解】。
if (! initInstance() || ! applicationDidFinishLaunching())
{
return 0;
}
//取得当前使用的OPENGL窗口管理实例对象
CCEGLView& mainWnd = CCEGLView::sharedOpenGLView();
//将窗口居中显示
mainWnd.centerWindow();
ShowWindow(mainWnd.getHWnd(), SW_SHOW);
//非常熟悉!进入WINDOWS消息循环
while (1)
{
//如果没有获取到WINDOWS消息
if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// 取得当前的计数值,即频率x当前时间
QueryPerformanceCounter(&nNow);
//m_nAnimationInterval.QuadPart的值 为setAnimationInterval函数进行设置的固定值。此处是为了判断时间流逝了多久,是否应该更新显示设备
if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)
{
//如果时间流逝达到了设定的FPS时间差,则更新计数值。
nLast.QuadPart = nNow.QuadPart;
//这里是设备渲染场景的函数,【伏笔2后面会有讲解】
CCDirector::sharedDirector()->mainLoop();
}
else
{
//sleep0秒的意义是让CPU做下时间片切换,防止死循环而使系统其它程序得不到响应。
Sleep(0);
}
continue;
}
//有消息获取到
if (WM_QUIT == msg.message)
{
// 如果获取的消息是退出则退出循环。
break;
}
// 如果没有定义加速键或者处理完加速键信息
if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))
{
//处理Windows消息
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
示例6: PaHost_OpenStream
//.........这里部分代码省略.........
{
int i;
ERR_RPT(("Creation of requested Audio Output device '%s' failed.\n",
((pad->pad_lpGUID == NULL) ? "Default" : pad->pad_Info.name) ));
for( i=0; i<Pa_CountDevices(); i++ )
{
pad = Pa_GetInternalDevice( i );
if( pad->pad_Info.maxOutputChannels >= past->past_NumOutputChannels )
{
DBUG(("Try device '%s' instead.\n", pad->pad_Info.name ));
hr = DirectSoundCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSound, NULL );
if( hr == DS_OK )
{
ERR_RPT(("Using device '%s' instead.\n", pad->pad_Info.name ));
break;
}
}
}
}
if( hr != DS_OK )
{
ERR_RPT(("PortAudio: DirectSoundCreate() failed!\n"));
result = paHostError;
sPaHostError = hr;
goto error;
}
hr = DSW_InitOutputBuffer( dsw,
(unsigned long) (past->past_SampleRate + 0.5),
past->past_NumOutputChannels, numBytes );
DBUG(("DSW_InitOutputBuffer() returns %x\n", hr));
if( hr != DS_OK )
{
result = paHostError;
sPaHostError = hr;
goto error;
}
past->past_FrameCount = pahsc->pahsc_DSoundWrapper.dsw_FramesWritten;
}
#if SUPPORT_AUDIO_CAPTURE
/* ------------------ INPUT */
if( (past->past_InputDeviceID >= 0) && (past->past_NumInputChannels > 0) )
{
pad = Pa_GetInternalDevice( past->past_InputDeviceID );
hr = DirectSoundCaptureCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSoundCapture, NULL );
/* If this fails, then try each input device until we find one that works. */
if( hr != DS_OK )
{
int i;
ERR_RPT(("Creation of requested Audio Capture device '%s' failed.\n",
((pad->pad_lpGUID == NULL) ? "Default" : pad->pad_Info.name) ));
for( i=0; i<Pa_CountDevices(); i++ )
{
pad = Pa_GetInternalDevice( i );
if( pad->pad_Info.maxInputChannels >= past->past_NumInputChannels )
{
PRINT(("Try device '%s' instead.\n", pad->pad_Info.name ));
hr = DirectSoundCaptureCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSoundCapture, NULL );
if( hr == DS_OK ) break;
}
}
}
if( hr != DS_OK )
{
ERR_RPT(("PortAudio: DirectSoundCaptureCreate() failed!\n"));
result = paHostError;
sPaHostError = hr;
goto error;
}
hr = DSW_InitInputBuffer( dsw,
(unsigned long) (past->past_SampleRate + 0.5),
past->past_NumInputChannels, numBytes );
DBUG(("DSW_InitInputBuffer() returns %x\n", hr));
if( hr != DS_OK )
{
ERR_RPT(("PortAudio: DSW_InitInputBuffer() returns %x\n", hr));
result = paHostError;
sPaHostError = hr;
goto error;
}
}
#endif /* SUPPORT_AUDIO_CAPTURE */
/* Calculate scalar used in CPULoad calculation. */
{
LARGE_INTEGER frequency;
if( QueryPerformanceFrequency( &frequency ) == 0 )
{
pahsc->pahsc_InverseTicksPerUserBuffer = 0.0;
}
else
{
pahsc->pahsc_InverseTicksPerUserBuffer = past->past_SampleRate /
( (double)frequency.QuadPart * past->past_FramesPerUserBuffer );
DBUG(("pahsc_InverseTicksPerUserBuffer = %g\n", pahsc->pahsc_InverseTicksPerUserBuffer ));
}
}
return result;
error:
PaHost_CloseStream( past );
return result;
}
示例7: main
//.........这里部分代码省略.........
queue.enqueueWriteBuffer(bufferD,CL_TRUE,0,n*d*sizeof(float),data);
queue.enqueueWriteBuffer(bufferC,CL_TRUE,0,d*k*sizeof(float),centroid);
//read the program source
std::ifstream sourceFile("kmeans_kernel.cl");
std::string sourceCode(std::istreambuf_iterator<char>(sourceFile),(std::istreambuf_iterator<char>()));
cl::Program::Sources source(1,std::make_pair(sourceCode.c_str(),sourceCode.length()+1));
//make program from source code
cl::Program program=cl::Program(context,source);
//build the program for the devices
program.build(devices);
//make kernel
//cl::Kernel vecadd_kernel(program,"kmeans");
cl::Kernel vecadd_kernel(program,"kmeans2");
//set the kernel arguments
vecadd_kernel.setArg(0,bufferD);
vecadd_kernel.setArg(1,bufferC);
//vecadd_kernel.setArg(2,bufferDS); //kmeans
vecadd_kernel.setArg(2,bufferClusterI); //kmeans2
vecadd_kernel.setArg(3,n);
vecadd_kernel.setArg(4,d);
vecadd_kernel.setArg(5,k);
//execute the kernel
cl::NDRange global(n);
cl::NDRange local(256);
cl::Event timing_event; //perf
//cl_int err_code; //perf
queue.enqueueNDRangeKernel(vecadd_kernel,cl::NullRange,global,local,NULL,&timing_event);
queue.finish();
cl_ulong gpu_starttime;
cl_ulong gpu_endtime;
gpu_starttime = timing_event.getProfilingInfo<CL_PROFILING_COMMAND_START>();
gpu_endtime = timing_event.getProfilingInfo<CL_PROFILING_COMMAND_END>();
double gpu_ms = 1e-6 * (gpu_endtime-gpu_starttime); //not sure where the 1e-6 came from, but AMD used 1e-9 for seconds
std::cout<<"GPU kmeans time="<<gpu_ms<<" milliseconds"<<std::endl;
//copy the output data back to the host
//queue.enqueueReadBuffer(bufferDS,CL_TRUE,0,n*k*sizeof(float),dist2); //kmeans
queue.enqueueReadBuffer(bufferClusterI,CL_TRUE,0,n*sizeof(int),clusterI); //kmeans2
//check the output - kmeans
//for (int i=0; i<n; i++) { //loop through all data lines
// std::cout<<"dist2 i="<<i<<" : ";
// for (int c=0; c<k; c++) { //loop through all centroids and compare this line to each
// float sum=0;
// for (int j=0; j<d; j++) { //loop through all values on each data line (dimensionality of data points)
// sum+=pow(data[i*d+j]-centroid[c*d+j],2);
// }
// float gpu_value = dist2[i*k+c];
// float error = gpu_value-sum; //error between this data point and centroid c location
// std::cout<<error<<" ";
// }
// std::cout<<std::endl;
//}
//Do a CPU version of kmeans to check the GPU data against
int *cpu_clusterI=new int[n];
LARGE_INTEGER frequency,counter1,counter2;
QueryPerformanceFrequency(&frequency); //returns counts per second
QueryPerformanceCounter(&counter1);
kmeans_cpu(data,centroid,cpu_clusterI,n,d,k);
QueryPerformanceCounter(&counter2);
float t_ms=((float)(counter2.LowPart-counter1.LowPart))/(float)(frequency.LowPart)*1000; //milliseconds
std::cout<<"CPU kmeans time="<<t_ms<<" milliseconds"<<std::endl;
//check output - kmeans2
bool result=true;
for (int i=0; i<n; i++) { //loop through all data lines
int gpu_index = clusterI[i]; //cluster index as calculated by the gpu
int cpu_index = cpu_clusterI[i]; //cluster index as calculated by the cpu
//std::cout<<"output i="<<i<<" : "<<gpu_index<<" "<<cpu_index<<std::endl;
if (gpu_index!=cpu_index) {
std::cout<<"Failed: "<<"output i="<<i<<" : "<<gpu_index<<" "<<cpu_index<<std::endl;
result=false;
break;
}
}
if (result)
std::cout<<"Success"<<std::endl;
//and don't forget to clean up here
delete [] data;
delete [] centroid;
//delete [] dist2;
delete [] clusterI;
delete [] cpu_clusterI;
}
catch (cl::Error error) {
std::cout<<error.what()<<"("<<error.err()<<")"<<std::endl;
}
return 0;
}
示例8: main
//.........这里部分代码省略.........
player.SetCurrentPort(eMapDest::South);
Item* itemCi = new Item("Iron Ore", 1);
player.getItems()->addItem(itemCi);
Item* itemCb = new Item("Bronze Ore", 1);
player.getItems()->addItem(itemCb);
Vendor vN;
Item* itemG = new Item("Gold Ore", 1000);
vN.getItems()->addItem(itemG);
Vendor vS;
Item* itemI = new Item("Iron Ore", 1000);
vS.getItems()->addItem(itemI);
Vendor vE;
Item* itemB = new Item("Bronze Ore", 1000);
vE.getItems()->addItem(itemB);
// Make the menus
MainMenu mainMenu(device);
MapMenu mapMenu(device, driver);
mapMenu.SetPlayer(&player);
TradeMenu tradeMenu(device, driver);
tradeMenu.SetPlayer(&player);
tradeMenu.SetVendor(&vS);
CraftingMenu craftMenu(device, driver);
craftMenu.SetPlayer(&player);
//////////////////////////////////////////////////////////////////////////
// Initialize timer to compute elapsed time between frames
//////////////////////////////////////////////////////////////////////////
__int64 cntsPerSec = 0;
QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
float secsPerCnt = 1.0f / (float)cntsPerSec;
__int64 prevTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
while (device->run())
{
//for scaling animation by time, not by frame
__int64 currTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;
sun_node->setRotation(vector3df(sun_angle, 0.0f, 0.0f));
sun_angle += dt;
if ((sun_angle > 0 && sun_angle < 109) || (sun_angle>350))
{
timer++;
if (timer > 10)
{
if (skyR < 100) skyR += 1;
if (skyG < 100) skyG += 1;
if (skyB < 140) skyB += 1;
timer = 0;
}
}
if (sun_angle > 170 && sun_angle < 330)
{
timer++;
if (timer > 10)
{
if (skyR > 0) skyR -= 1;
if (skyG > 0) skyG -= 1;
示例9: main
int __cdecl main(int argc,char *argv[])
{
int i,arg, currit, modes, modenr;
paramT *p;
#ifdef SHAREDMEM
int shmid;
#endif
#ifdef WIN32
DWORD procID;
HANDLE hProcess;
HANDLE hThread[10];
DWORD IDThread;
LARGE_INTEGER lpFrequency;
#endif
p = (paramT*) malloc(MXPROC*sizeof(paramT));
/* default initialisation */
modes=0;
p[0].mode=0;
p[0].npes=NPES;
p[0].mxsize=MXRUNSZ;
p[0].minsize=MINRUNSZ;
p[0].mxstrds=MXSTRDS;
p[0].mxiters=MXIT;
p[0].currentrep=1;
#ifdef HAVEOPT
p[0].useoptasm=OPTASM;
#else
p[0].useoptasm=0;
#endif
arg=1;
chartrev=CHARTREV;
printf("\nECT memperf - Extended Copy Transfer Characterization\n");
printf("Memory Performance Characterization Toolkit %s\n\n",VERSION);
#ifdef WIN32
/* lookup clock frequency */
QueryPerformanceFrequency(&lpFrequency);
tic = (lpFrequency.LowPart / 1000000.0);
tic += (lpFrequency.HighPart * (2^32) / 1000000.0);
#else
tic=getcpufrequency();
#endif
if (argc<2) {
#ifdef WIN32
printf("Usage: %s -m <mode> [-p] [-s] [-n] [-r] [-i] [-c] [-o]\n",argv[0]);
#elif defined HAVEOPT
printf("Usage: %s -m <mode> [-p] [-s] [-n] [-r] [-i] [-t] [-c] [-a] [-o]\n",argv[0]);
#else
printf("Usage: %s -m <mode> [-p] [-s] [-n] [-r] [-i] [-t] [-c] [-o]\n",argv[0]);
#endif /*WIN32*/
printf(" -m <mode> : 0 = load sum test\n");
printf(" 1 = const store test\n");
printf(" 2 = load copy test\n");
printf(" 3 = copy store test\n");
printf(" 9 = all tests\n");
printf(" [-c <nofrep> ] Default: %d\n", NROFREP);
#ifdef HAVEOPT
printf(" [-a <optasm> ] 0/1 = use/don't use special instructions\n");
printf(" 2 = both methods, Default: %d\n", OPTASM);
#endif
printf(" [-p <nProc> ] Default: %d\n",NPES);
printf(" [-s <mxstrds>] Default: %d\n",MXSTRDS);
printf(" [-n <mxsize> ] Default: %d (%d Bytes)\n",MXRUNSZ,8<<MXRUNSZ);
printf(" [-r <minsize>] Default: %d (%d Bytes)\n",MINRUNSZ,8<<MINRUNSZ);
printf(" [-i <mxiters>] Default: %d\n",MXIT);
printf(" [-o ] Reversed Output\n");
#ifdef WIN32
printf(" Evaluated clock resolution [MHz]: %.2f\n",tic);
#else
printf(" [-t <tics/us>] Default: %.2f\n",tic);
#endif
exit(2);
}
while (arg<argc) {
if (argv[arg][0]=='-') {
if (argv[arg][1]=='p' && (arg+1)<argc) {
arg++; p[0].npes=atoi(argv[arg]);
}
if (argv[arg][1]=='s' && (arg+1)<argc) {
arg++; p[0].mxstrds=atoi(argv[arg]);
}
if (argv[arg][1]=='m' && (arg+1)<argc) {
arg++; modes=atoi(argv[arg]);
}
if (argv[arg][1]=='n' && (arg+1)<argc) {
arg++; p[0].mxsize=atoi(argv[arg]);
}
if (argv[arg][1]=='r' && (arg+1)<argc) {
arg++; p[0].minsize=atoi(argv[arg]);
}
if (argv[arg][1]=='i' && (arg+1)<argc) {
arg++; p[0].mxiters=atoi(argv[arg]);
}
if (argv[arg][1]=='o') {
//.........这里部分代码省略.........
示例10: claw_get_seconds
// utilities
double claw_get_seconds (void) {
LARGE_INTEGER count, frequency;
QueryPerformanceFrequency (&frequency);
QueryPerformanceCounter (&count);
return (double)count.QuadPart/frequency.QuadPart;
}
示例11: defined
RakNetTimeNS RakNet::GetTimeNS( void )
{
#if defined(_PS3)
uint64_t curTime;
if ( initialized == false)
{
ticksPerSecond = _PS3_GetTicksPerSecond();
// Use the function to get elapsed ticks, this is a macro.
_PS3_GetElapsedTicks(curTime);
uint64_t quotient, remainder;
quotient=(curTime / ticksPerSecond);
remainder=(curTime % ticksPerSecond);
initialTime = (RakNetTimeNS) quotient*(RakNetTimeNS)1000000 + (remainder*(RakNetTimeNS)1000000 / ticksPerSecond);
initialized = true;
}
#elif defined(_WIN32)
// Win32
if ( initialized == false)
{
initialized = true;
#if !defined(_WIN32_WCE)
// Save the current process
HANDLE mProc = GetCurrentProcess();
// Get the current Affinity
#if _MSC_VER >= 1400 && defined (_M_X64)
GetProcessAffinityMask(mProc, (PDWORD_PTR)&mProcMask, (PDWORD_PTR)&mSysMask);
#else
GetProcessAffinityMask(mProc, &mProcMask, &mSysMask);
#endif
mThread = GetCurrentThread();
#endif // !defined(_WIN32_WCE)
QueryPerformanceFrequency( &yo );
}
// 01/12/08 - According to the docs "The frequency cannot change while the system is running." so this shouldn't be necessary
/*
if (++queryCount==200)
{
// Set affinity to the first core
SetThreadAffinityMask(mThread, 1);
QueryPerformanceFrequency( &yo );
// Reset affinity
SetThreadAffinityMask(mThread, mProcMask);
queryCount=0;
}
*/
#elif (defined(__GNUC__) || defined(__GCCXML__))
if ( initialized == false)
{
gettimeofday( &tp, 0 );
initialized=true;
// I do this because otherwise RakNetTime in milliseconds won't work as it will underflow when dividing by 1000 to do the conversion
initialTime = ( tp.tv_sec ) * (RakNetTimeNS) 1000000 + ( tp.tv_usec );
}
#endif
#if defined(_PS3)
// Use the function to get elapsed ticks, this is a macro.
_PS3_GetElapsedTicks(curTime);
uint64_t quotient, remainder;
quotient=(curTime / ticksPerSecond);
remainder=(curTime % ticksPerSecond);
curTime = (RakNetTimeNS) quotient*(RakNetTimeNS)1000000 + (remainder*(RakNetTimeNS)1000000 / ticksPerSecond);
// Subtract from initialTime so the millisecond conversion does not underflow
return curTime - initialTime;
#elif defined(_WIN32)
RakNetTimeNS curTime;
static RakNetTimeNS lastQueryVal=(RakNetTimeNS)0;
// static unsigned long lastTickCountVal = GetTickCount();
LARGE_INTEGER PerfVal;
#if !defined(_WIN32_WCE)
// Set affinity to the first core
SetThreadAffinityMask(mThread, 1);
#endif // !defined(_WIN32_WCE)
// Docs: 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.
// Query the timer
QueryPerformanceCounter( &PerfVal );
#if !defined(_WIN32_WCE)
// Reset affinity
SetThreadAffinityMask(mThread, mProcMask);
#endif // !defined(_WIN32_WCE)
__int64 quotient, remainder;
quotient=((PerfVal.QuadPart) / yo.QuadPart);
remainder=((PerfVal.QuadPart) % yo.QuadPart);
curTime = (RakNetTimeNS) quotient*(RakNetTimeNS)1000000 + (remainder*(RakNetTimeNS)1000000 / yo.QuadPart);
//.........这里部分代码省略.........
示例12: CStopwatch
CStopwatch() { QueryPerformanceFrequency(&m_liPerfFreq); Start(); }
示例13: GetTimeNow
CmcDateTime CmcDateTime::GetTimeNow ()
{
static bool bFirstTime = true;
static CmcDateTime last_date;
static LARGE_INTEGER last_time;
static LONGLONG iCounterFrequency = 0;
if (bFirstTime)
{
bFirstTime = false;
LARGE_INTEGER large_int_frequency;
if (QueryPerformanceFrequency (&large_int_frequency))
{
iCounterFrequency = large_int_frequency.QuadPart;
QueryPerformanceCounter (&last_time);
}
}
double secs = 0;
LARGE_INTEGER time_now;
if (iCounterFrequency)
{
QueryPerformanceCounter (&time_now);
LONGLONG offset = time_now.QuadPart - last_time.QuadPart;
secs = (double) offset / (double) iCounterFrequency;
// TRACE ("Secs = %10.4f\n", secs);
}
else
{
time_now.QuadPart = 0;
time_now.QuadPart = 0;
}
// if no high-performance counter, just query the time each time
if (iCounterFrequency == 0 ||
last_date.m_dt == 0 ||
secs > RESYNC_EVERY_SECS)
{
SYSTEMTIME systime;
GetLocalTime (&systime);
last_date = CmcDateTime(systime.wYear, systime.wMonth,
systime.wDay, systime.wHour, systime.wMinute,
(double) systime.wSecond + ( (double) systime.wMilliseconds / 1000.0) );
secs = 0;
last_time = time_now;
}
CmcDateTime this_date (last_date);
this_date.m_dt += secs / SECS_IN_DAY;
// ---- debugging
#if 0
{
SYSTEMTIME systime;
GetSystemTime (&systime);
CmcDateTime test = CmcDateTime(systime.wYear, systime.wMonth,
systime.wDay, systime.wHour, systime.wMinute,
(double) systime.wSecond + ( (double) systime.wMilliseconds / 1000.0) );
double diff = test.m_dt - this_date.m_dt;
TRACE1 ("Time difference = %10.8f\n", diff);
}
#endif
// --- end debugging
return this_date;
}
示例14: PerformanceFreqHolder
PerformanceFreqHolder()
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
value = freq.QuadPart;
}
示例15: gettimeofday
int gettimeofday(struct timeval* tp, int* /*tz*/) {
static LARGE_INTEGER tickFrequency, epochOffset;
static Boolean isInitialized = False;
LARGE_INTEGER tickNow;
#if !defined(_WIN32_WCE)
QueryPerformanceCounter(&tickNow);
#else
tickNow.QuadPart = GetTickCount();
#endif
if (!isInitialized) {
if(1 == InterlockedIncrement(&initializeLock_gettimeofday)) {
#if !defined(_WIN32_WCE)
// For our first call, use "ftime()", so that we get a time with a proper epoch.
// For subsequent calls, use "QueryPerformanceCount()", because it's more fine-grain.
struct timeb tb;
ftime(&tb);
tp->tv_sec = tb.time;
tp->tv_usec = 1000*tb.millitm;
// Also get our counter frequency:
QueryPerformanceFrequency(&tickFrequency);
#else
/* FILETIME of Jan 1 1970 00:00:00. */
const LONGLONG epoch = 116444736000000000LL;
FILETIME fileTime;
LARGE_INTEGER time;
GetSystemTimeAsFileTime(&fileTime);
time.HighPart = fileTime.dwHighDateTime;
time.LowPart = fileTime.dwLowDateTime;
// convert to from 100ns time to unix timestamp in seconds, 1000*1000*10
tp->tv_sec = (long)((time.QuadPart - epoch) / 10000000L);
/*
GetSystemTimeAsFileTime has just a seconds resolution,
thats why wince-version of gettimeofday is not 100% accurate, usec accuracy would be calculated like this:
// convert 100 nanoseconds to usec
tp->tv_usec= (long)((time.QuadPart - epoch)%10000000L) / 10L;
*/
tp->tv_usec = 0;
// resolution of GetTickCounter() is always milliseconds
tickFrequency.QuadPart = 1000;
#endif
// compute an offset to add to subsequent counter times, so we get a proper epoch:
epochOffset.QuadPart
= tp->tv_sec * tickFrequency.QuadPart + (tp->tv_usec * tickFrequency.QuadPart) / 1000000L - tickNow.QuadPart;
// next caller can use ticks for time calculation
isInitialized = True;
return 0;
} else {
InterlockedDecrement(&initializeLock_gettimeofday);
// wait until first caller has initialized static values
while(!isInitialized){
Sleep(1);
}
}
}
// adjust our tick count so that we get a proper epoch:
tickNow.QuadPart += epochOffset.QuadPart;
tp->tv_sec = (long)(tickNow.QuadPart / tickFrequency.QuadPart);
tp->tv_usec = (long)(((tickNow.QuadPart % tickFrequency.QuadPart) * 1000000L) / tickFrequency.QuadPart);
return 0;
}