青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

《windows圖形編程》有講:

KTimer.h

#pragma?once
inline?unsigned?__int64?GetCycleCount(
void )
{
????_asm?_emit?
0x0F
????_asm?_emit?
0x31
}


class ?KTimer??
{
????unsigned?__int64?m_startcycle;
public :
????unsigned?__int64?m_overhead;????
// RTSC指令的運(yùn)行時(shí)間

????KTimer()
????
{
????????m_overhead?
= ? 0 ;
????????Start();
????????m_overhead?
= ?Stop();
????}

????
void ?Start();
????unsigned?__int64?Stop();
????unsigned?unsigned?GetCPUSpeed();

}
;

KTimer.cpp
#include?"KTimer.h"

#include?
<iostream>
#include?
<windows.h>


void?KTimer::Start()
{
????m_startcycle?
=?GetCycleCount();
}

unsigned?__int64?KTimer::Stop()
{
????
return?GetCycleCount()?-?m_startcycle?-?m_overhead;
}

unsigned?unsigned?KTimer::GetCPUSpeed()
{
????cout?
<<?"開(kāi)始測(cè)試?cpu速度.."?<<?endl;
????Start();
????Sleep(
1000);
????unsigned?cputime?
=?Stop();
????unsigned?cpuspeed10?
=?(unsigned)(cputime/100000);
????cout?
<<?"CPU速度?每秒:"?<<?cputime?<<?"?clocks"?<<?endl;
????
return?cpuspeed10?==?0???1?:?cpuspeed10;
}

用法:
#include?"stdafx.h"
#include?
<tchar.h>
#include?
<windows.h>
#include?
<iostream>

#include?
"KTimer.h"

int?main(int?argc,?char*?argv[])
{????
????KTimer?timer;

????unsigned?cpuspeed10?
=?timer.GetCPUSpeed();

????timer.Start();
????
//做耗時(shí)操作
????
????unsigned?time?
=?timer.Stop();

????TCHAR?mess[
128];
????wsprintf(mess,_T(
"耗時(shí):%d?ns"),?time?*?10000?/?cpuspeed10);
????cout?
<<?mess?<<?endl;

????
return?0;
}

Feedback

# re: 計(jì)時(shí)輔助類(lèi)  回復(fù)  更多評(píng)論   

2006-09-25 17:44 by 子彈
//========================================================================
// CPUSPEED
//
// CPU Timer for the Action, Arcade, Strategy Games Group, a part of
// the Entertainment Business Unit at Microsoft.
//
// (c) Copyright 1999-2000 Microsoft Corporation.
// Written by Michael Lyons
//
// USED WITH PERMISSION
//
//========================================================================

//========================================================================
// Content References in Game Coding Complete 2nd Edition
//
// GetCPUSpeed - Chapter 5, page 135
//========================================================================


#include "GameCodeStd.h"

#define SLEEPTIME 0


//========================================================================
// define static variables
//========================================================================
static int s_milliseconds;
static __int64 s_ticks;

static int s_milliseconds0;
static __int64 s_ticks0;

//========================================================================
// fabs
//
// floating point absolute value function
//========================================================================
#if 0
#pragma message("Dsiabled local fabs()implementation to prevent collision w/impl in VS.NET 2k3")
float inline fabs(float a)
{
if (a < 0.0f)
return -a;
else
return a;
}
#endif
//========================================================================
// StartTimingCPU
//
// Call this function to start timing the CPU. It takes the CPU tick
// count and the current time and stores it. Then, while you do other
// things, and the OS task switches, the counters continue to count, and
// when you call UpdateCPUTime, the measured speed is accurate.
//
//========================================================================
int StartTimingCPU()
{
//
// detect ability to get info
//
__asm
{
pushfd ; push extended flags
pop eax ; store eflags into eax
mov ebx, eax ; save EBX for testing later
xor eax, (1<<21) ; switch bit 21
push eax ; push eflags
popfd ; pop them again
pushfd ; push extended flags
pop eax ; store eflags into eax
cmp eax, ebx ; see if bit 21 has changed
jz no_cpuid ; make sure it's now on
}

//
// make ourselves high priority just for the time between
// when we measure the time and the CPU ticks
//
DWORD dwPriorityClass = GetPriorityClass(GetCurrentProcess());
int dwThreadPriority = GetThreadPriority(GetCurrentThread());
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);

//
// start timing
//
s_milliseconds0 = (int)timeGetTime();

__asm
{
lea ecx, s_ticks0 ; get the offset
mov dword ptr [ecx], 0 ; zero the memory
mov dword ptr [ecx+4], 0 ;
rdtsc ; read time-stamp counter
mov [ecx], eax ; store the negative
mov [ecx+4], edx ; in the variable
}

//
// restore thread priority
//
SetThreadPriority(GetCurrentThread(), dwThreadPriority);
SetPriorityClass(GetCurrentProcess(), dwPriorityClass);

return 0;

no_cpuid:
return -1;
}

//========================================================================
// UpdateCPUTime
//
// This function stops timing the CPU by adjusting the timers to account
// for the amount of elapsed time and the number of CPU cycles taked
// during the timing period.
//========================================================================
void UpdateCPUTime()
{
//
// make ourselves high priority just for the time between
// when we measure the time and the CPU ticks
//
DWORD dwPriorityClass = GetPriorityClass(GetCurrentProcess());
int dwThreadPriority = GetThreadPriority(GetCurrentThread());
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);

//
// get the times
//
s_milliseconds = -s_milliseconds0;
s_ticks = -s_ticks0;

s_milliseconds += (int)timeGetTime();

__asm
{
lea ecx, s_ticks ; get the offset
rdtsc ; read time-stamp counter
add [ecx], eax ; add the tick count
adc [ecx+4], edx ;
}

//
// restore thread priority
//
SetThreadPriority(GetCurrentThread(), dwThreadPriority);
SetPriorityClass(GetCurrentProcess(), dwPriorityClass);

return;
}

//========================================================================
// CalcCPUSpeed
//
// This function takes the measured values and returns a speed that
// represents a common possible CPU speed.
//========================================================================
int CalcCPUSpeed()
{
//
// get the actual cpu speed in MHz, and
// then find the one in the CPU speed list
// that is closest
//
const struct tagCPUSPEEDS
{
float fSpeed;
int iSpeed;
} cpu_speeds[] =
{
//
// valid CPU speeds that are not integrally divisible by
// 16.67 MHz
//
{ 60.00f, 60 },
{ 75.00f, 75 },
{ 90.00f, 90 },
{ 120.00f, 120 },
{ 180.00f, 180 },
};

//
// find the closest one
//
float fSpeed=((float)s_ticks)/((float)s_milliseconds*1000.0f);
int iSpeed=cpu_speeds[0].iSpeed;
float fDiff=(float)fabs(fSpeed-cpu_speeds[0].fSpeed);

for (int i=1 ; i<sizeof(cpu_speeds)/sizeof(cpu_speeds[0]) ; i++)
{
float fTmpDiff = (float)fabs(fSpeed-cpu_speeds[i].fSpeed);

if (fTmpDiff < fDiff)
{
iSpeed=cpu_speeds[i].iSpeed;
fDiff=fTmpDiff;
}
}

//
// now, calculate the nearest multiple of fIncr
// speed
//

//
// now, if the closest one is not within one incr, calculate
// the nearest multiple of fIncr speed and see if that's
// closer
//
const float fIncr=16.66666666666666666666667f;
const int iIncr=4267; // fIncr << 8

//if (fDiff > fIncr)
{
//
// get the number of fIncr quantums the speed is
//
int iQuantums = (int)((fSpeed / fIncr) + 0.5f);
float fQuantumSpeed = (float)iQuantums * fIncr;
float fTmpDiff = (float)fabs(fQuantumSpeed - fSpeed);

if (fTmpDiff < fDiff)
{
iSpeed = (iQuantums * iIncr) >> 8;
fDiff=fTmpDiff;
}
}

return iSpeed;
}


//========================================================================
// GetCPUSpeed
//
// Gets the CPU speed by timing it for 1 second.
//========================================================================
int GetCPUSpeed()
{
static int CPU_SPEED = 0;

if(CPU_SPEED!=0)
{
//This will assure that the 0.5 second delay happens only once
return CPU_SPEED;
}

if (StartTimingCPU())
return 0;

//This will lock the application for 1 second
do
{
UpdateCPUTime();
Sleep(SLEEPTIME);
} while (s_milliseconds < 1000);

CPU_SPEED = CalcCPUSpeed();
return CPU_SPEED;
}


代碼是《Game Coding Complete》上的……


只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美激情在线免费观看| 一区二区三区成人 | 亚洲国产裸拍裸体视频在线观看乱了中文 | 国产综合av| 老司机aⅴ在线精品导航| 久久国产色av| 久久精品亚洲一区| 久久久久国内| 美国十次了思思久久精品导航| 久久aⅴ国产欧美74aaa| 久久只有精品| 欧美精品久久久久久久| 欧美精品电影在线| 国产精品久久91| 国产精品入口尤物| 一区二区在线视频| 亚洲美女av网站| 午夜精品一区二区在线观看| 欧美专区在线播放| 欧美黄色影院| 亚洲与欧洲av电影| 久久久久看片| 欧美日韩在线三区| 国语精品一区| 中国女人久久久| 久久亚洲欧美| 亚洲美女视频在线观看| 久久国产精品99国产| 欧美日本在线视频| 国产欧美日韩一区二区三区在线观看| 亚洲大片一区二区三区| 亚洲私拍自拍| 亚洲高清123| 亚洲欧美国产77777| 免费日韩av| 国产日韩欧美在线视频观看| 日韩一二在线观看| 久久久亚洲一区| 一区二区三区欧美日韩| 久久久99国产精品免费| 欧美三级在线播放| 亚洲精品永久免费精品| 老司机精品导航| 中日韩美女免费视频网站在线观看| 久久综合狠狠综合久久综青草 | 久久国产精品99精品国产| 欧美精品久久久久久| 国内成人精品视频| 亚洲女与黑人做爰| 亚洲人体1000| 久久婷婷久久一区二区三区| 国产欧美日韩高清| 亚洲综合999| 日韩一级精品| 欧美日韩成人一区二区| 亚洲日本欧美| 麻豆成人av| 久久久成人精品| 午夜在线不卡| 亚洲精品一区二区在线| 欧美gay视频激情| 久久福利影视| 狠狠色综合网| 嫩草影视亚洲| 快播亚洲色图| 亚洲欧洲精品一区二区三区波多野1战4 | 国产一区二区三区在线观看视频 | 一本到高清视频免费精品| 久久久久久久久久久久久久一区| 亚洲一二三区在线| 国产精品乱人伦一区二区| 亚洲一区二区三区视频| 日韩午夜电影av| 欧美精品在线观看91| 在线性视频日韩欧美| 亚洲日本成人| 欧美日韩一区二区三区免费| 亚洲影视九九影院在线观看| 亚洲私人影院| 国产一区二区三区四区| 欧美福利一区二区三区| 欧美国产日韩精品| 亚洲一区在线观看视频 | 亚洲欧美伊人| 欧美在线观看一区二区三区| 精久久久久久| 亚洲第一主播视频| 欧美无乱码久久久免费午夜一区 | 亚洲成人在线视频网站| 欧美日韩播放| 久久精品成人| 欧美va天堂| 亚洲一区二区网站| 午夜久久久久久| 亚洲国产一区二区三区在线播| 亚洲区国产区| 国产视频自拍一区| 欧美国产亚洲精品久久久8v| 欧美日韩少妇| 久久久久天天天天| 欧美日本免费| 久久亚洲欧美国产精品乐播| 欧美大尺度在线观看| 国产在线不卡精品| 国产精品久久二区| 久久激五月天综合精品| 欧美精品导航| 亚洲欧美激情一区二区| 久久久久久久91| 亚洲婷婷在线| 久久亚洲精品伦理| 亚洲一区二区三区久久| 欧美国产日韩亚洲一区| 久久久久国产精品一区| 欧美日本亚洲韩国国产| 美女视频黄 久久| 国产精品女人久久久久久| 欧美大尺度在线| 国产欧美一区二区白浆黑人| 亚洲精品国产精品国自产观看浪潮| 国产伦精品一区二区三区四区免费| 欧美激情一区三区| 黄色亚洲免费| 亚洲一区二区成人在线观看| 亚洲成色www8888| 欧美专区福利在线| 久久成人人人人精品欧| 国产精品扒开腿做爽爽爽视频 | 亚洲欧美日韩在线一区| 亚洲午夜精品一区二区| 欧美国产欧美综合| 欧美国产视频一区二区| 亚洲激情在线激情| 免费久久99精品国产| 欧美二区在线播放| 亚洲第一天堂av| 久久深夜福利免费观看| 老司机免费视频久久| 激情av一区| 麻豆国产精品一区二区三区 | 在线观看的日韩av| 久久精品国产亚洲一区二区| 久久久午夜精品| 伊人久久亚洲热| 久久一区免费| 91久久中文| 亚洲午夜精品| 国产欧美欧洲在线观看| 欧美影院精品一区| 久热精品视频在线观看一区| 亚洲丁香婷深爱综合| 免费成人黄色av| 亚洲黄色免费| 亚洲午夜一二三区视频| 国产精品系列在线| 久久精品亚洲| 亚洲激情精品| 亚洲欧美日韩精品| 好吊色欧美一区二区三区视频| 久久久精品国产免费观看同学| 欧美a级片网站| 日韩一级黄色大片| 国产精品视频xxx| 久久精品欧美日韩| 91久久精品国产91久久性色| 亚洲欧美精品伊人久久| 精久久久久久| 欧美日本一区二区视频在线观看| 洋洋av久久久久久久一区| 欧美激情一区二区三区四区| 日韩网站在线看片你懂的| 欧美日韩综合在线| 久久黄金**| 日韩亚洲精品电影| 久久综合伊人77777麻豆| 一本到高清视频免费精品| 国内精品一区二区三区| 欧美久久久久久久久| 午夜精品剧场| 亚洲人在线视频| 久久激情久久| 在线亚洲欧美| 亚洲国产日韩美| 欧美日韩高清一区| 亚洲一区观看| 亚洲精一区二区三区| 欧美在线关看| 亚洲电影免费在线| 欧美va天堂在线| 午夜在线视频观看日韩17c| 亚洲三级影院| 久久裸体艺术| 亚洲午夜精品久久| 欧美国产视频在线观看| 久久福利视频导航| 一区二区三区 在线观看视频 | 99亚洲伊人久久精品影院红桃| 久久免费的精品国产v∧| 亚洲一区高清| 夜夜狂射影院欧美极品|