由于别人可以通过修改注册表或截获系统函数,是我无法信任我得到的结果,所以,最好能介绍一种独立的测试方法
解决方案 »
- 询问个LoadLibrary的问题
- 哪位有可以编译的windows核心编程的源码?
- 工作2年多了,越来越凄凉,想换换环境了,大家给给意见好吗
- CSession对象能跨线程使用?
- 自绘按钮的问题,急!!!!
- 一个使用CList而产生的问题,请指教!并请大家谈谈对MFC的模板类的看法。
- 如何分割一个view的界面,使得左边是CTreeCtrl,右边是CListCtrl,并且可以改变大小?
- ado 怎么用存储过程输入和取得datetime类型的参数啊? 200分送
- 在ATL中如何定义CWND*窗口句柄类型的参数?
- 如何例CStatic接受双击事件?
- abc_rain进来拿分
- 请问OLE DB的问题,为什么只能读不能添加和删除!
#pragma onceinline unsigned __int64 GetCycleCount(void)
{
_asm _emit 0x0F
_asm _emit 0x31
}class KTimer
{
unsigned __int64 m_startcycle;public: unsigned __int64 m_overhead; KTimer(void)
{
m_overhead = 0;
Start();
m_overhead = Stop();
} void Start(void)
{
m_startcycle = GetCycleCount();
} unsigned __int64 Stop(void)
{
return GetCycleCount()-m_startcycle-m_overhead;
}
};The KTimer class stores timing information in a 64-bit unsigned integer, because the 32-bit version lasts less than a second on a 200-MHz machine. The Get Cycle Count function returns a 64-bit unsigned integer representing the current CPU clock count. The result generated by the RDTSC instruction matches the C 64-bit function return value convention. So GetCycleCount is merely a single machine instruction. The Start function reads the starting clock count; Stop reads the end clock count and returns their difference. To be more accurate, we have to compensate for the time used by the RDTSC instructions and store its reading. The KTimer class constructor does this by starting and stopping the timer once to measure the amount of overhead, which can then be deducted later.Here is a sample program that uses KTimer to measure your CPU clock speed and the time it takes to create a solid brush:
// GDISpeed.cpp
#define STRICT
#define WIN32_LEAN_AND_MEAN#include <windows.h>
#include <tchar.h>#include "..\..\include\timer.h"int WINAPI WinMain(HINSTANCE hInst, HINSTANCE,
LPSTR lpCmd, int nShow)
{
KTimer timer;
TCHAR mess[128]; timer.Start();
Sleep(1000);
unsigned cpuspeed10 = (unsigned)(timer.Stop()/100000); timer.Start();
CreateSolidBrush(RGB(0xAA, 0xAA, 0xAA));
unsigned time = (unsigned) timer.Stop(); wsprintf(mess, _T("CPU speed %d.%d mhz\n")
_T("KTimer overhead %d clock cycles\n")
_T("CreateSolidBrush %d clock cycles %d ns"),
cpuspeed10 / 10, cpuspeed10 % 10,
(unsigned) timer.m_overhead,
time, time * 10000 / cpuspeed10; MessageBox(NULL, mess, _T("How fast is GDI?"), MB_OK); return 0;
}