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

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>
            亚洲欧美国产va在线影院| 久久av免费一区| 亚洲国产美女精品久久久久∴| 欧美日韩精品一区二区三区四区| 午夜精品久久久久| 亚洲国产日韩综合一区| 欧美午夜不卡在线观看免费 | 久久香蕉国产线看观看网| 一区二区不卡在线视频 午夜欧美不卡在 | 久久综合一区二区三区| 久久精品一区二区三区不卡| 久久精品国产77777蜜臀| 亚洲欧美日韩在线观看a三区| 原创国产精品91| 在线视频日韩精品| 亚洲欧美日韩第一区| 欧美成人一区二区| 久久亚洲不卡| 久久中文欧美| 国产精品久久久久久久久| 国产精品日本一区二区 | 久久―日本道色综合久久| 免费人成精品欧美精品| 国产乱肥老妇国产一区二| 亚洲毛片在线免费观看| 欧美激情自拍| 亚洲三级免费电影| 欧美中文在线观看国产| 亚洲美洲欧洲综合国产一区| 日韩一级片网址| 欧美激情中文字幕乱码免费| 国产精品系列在线播放| 亚洲午夜av电影| 99精品国产在热久久| 久久久精品午夜少妇| 国产亚洲精品成人av久久ww| 亚洲精品国产品国语在线app | 亚洲欧美精品在线观看| 欧美jjzz| 久久久久成人精品| 国产一区二区av| 午夜精品一区二区三区四区| 亚洲国产精品福利| 久久综合一区二区| 国产欧美精品一区aⅴ影院| 亚洲视频在线一区| aa级大片欧美三级| 欧美日韩亚洲高清| 一区二区三区色| 亚洲精品久久7777| 国产精品久久一区二区三区| 亚洲欧美美女| 午夜精品久久久久久久久久久| 国产精品欧美日韩| 久久亚洲影院| 欧美日韩免费看| 久久精品免费播放| 欧美激情亚洲激情| 久久野战av| 久久久久国产精品www| 亚洲精品久久久久| 欧美一区二区免费观在线| 狠狠色噜噜狠狠色综合久| 欧美成人免费在线视频| 国产欧美日韩精品丝袜高跟鞋 | 久久高清国产| 亚洲永久视频| 欧美日韩亚洲一区二区| 久久久久天天天天| 国产婷婷色一区二区三区在线| 欧美激情欧美狂野欧美精品| 国产麻豆91精品| 中文av一区特黄| 在线午夜精品| 欧美视频一区二| 亚洲国产一成人久久精品| 亚洲国产精品成人精品| 久久爱www.| 男女精品网站| 亚洲第一黄色| 欧美精品在线免费播放| 亚洲精品日韩精品| 香蕉视频成人在线观看| 国产欧美日韩一区二区三区在线| 亚洲欧美日韩精品久久久| 亚洲一级黄色| 韩国精品久久久999| 久热综合在线亚洲精品| 美女精品在线| 一区二区日韩免费看| 日韩视频中文| av成人免费在线观看| 欧美日韩国产综合视频在线观看中文 | 久久精品30| 亚洲国产清纯| 国产日韩欧美视频在线| 欧美成人影音| 久久精品在线| 亚洲美女在线视频| 欧美资源在线| 9久re热视频在线精品| 国产日韩欧美二区| 久久夜色精品国产欧美乱极品| 男人插女人欧美| 久久久国产精彩视频美女艺术照福利| 国内精品美女在线观看| 欧美三级韩国三级日本三斤| 欧美一区中文字幕| 一本久道久久久| 亚洲三级视频| 亚洲人成网在线播放| 玖玖精品视频| 欧美va亚洲va香蕉在线| 欧美电影免费观看高清完整版| 欧美一区二区三区日韩视频| 日韩视频在线观看一区二区| 在线欧美视频| 国产精品国产一区二区 | 欧美aaa级| 久久在精品线影院精品国产| 亚洲欧美高清| 亚洲字幕一区二区| 中文欧美字幕免费| 亚洲二区视频在线| 亚洲精品视频在线看| 久久久久高清| 欧美成人免费在线观看| 国产精品一区免费视频| 国产精品美女久久| 国产一本一道久久香蕉| 亚洲国产小视频| 午夜在线电影亚洲一区| 欧美一区二区三区免费在线看| 久久精品首页| 欧美成人精品在线播放| 欧美电影资源| 久久精品国产成人| 欧美日韩亚洲一区二区三区四区| 国产精品久久久一区二区三区| 伊人久久亚洲美女图片| 亚洲欧美日韩国产中文| 欧美激情导航| 久久美女性网| 国产一区二区三区自拍| 国内精品视频一区| 国产精品一区免费观看| 国产一区二区| 一区二区三区视频在线| 玖玖综合伊人| 久久精品30| 亚洲福利精品| 亚洲国产第一页| 久久成年人视频| 在线欧美不卡| 欧美大片免费观看在线观看网站推荐 | 美女国内精品自产拍在线播放| 欧美理论在线| 亚洲精品乱码久久久久| 免费欧美日韩| 免费毛片一区二区三区久久久| 国产在线乱码一区二区三区| 午夜精品久久久久久久男人的天堂| 亚洲美女毛片| 国产精品久久午夜夜伦鲁鲁| 亚洲欧美日韩综合国产aⅴ| 中国av一区| 亚洲二区在线观看| 亚洲黄页视频免费观看| 亚洲欧洲日韩综合二区| 国产精品视频第一区| 欧美黑人多人双交| 国产精品啊v在线| 欧美成熟视频| 国产精品自在欧美一区| 欧美国产激情| 国产人成一区二区三区影院| 欧美jizzhd精品欧美巨大免费| 欧美日韩在线播放一区二区| 久久综合狠狠| 国产亚洲在线| 亚洲综合成人在线| 亚洲美女一区| 欧美国产在线电影| 免费日韩成人| 亚洲电影专区| 巨乳诱惑日韩免费av| 老司机一区二区三区| 国产性天天综合网| 久久gogo国模啪啪人体图| 欧美亚洲免费电影| 国产欧美韩日| 久久久久久久波多野高潮日日| 久久精品一区二区三区不卡牛牛| 国产精品人成在线观看免费| 中文av一区二区| 久久久久久久网| 亚洲精品视频在线看| 欧美日韩国产欧美日美国产精品| 亚洲精品久久久久久久久| 国产精品99久久久久久宅男 |