QueryPerformanceFrequency,RDTSC,CPU频率
来源:互联网 发布:金牌商家网络评选 编辑:程序博客网 时间:2024/05/19 03:20
//warning C4035: 'RDTSC' : no return value
#pragma warning(disable:4035)
#include <Windows.h>
//RDTSC-Read Time-Stamp Counter
//自开机以来CPU经历的时钟周期数
unsigned __int64 RDTSC()
{
__asm _emit 0x0F;
__asm _emit 0x31;
}
//CPU的频率
double CpuFrequency()
{
//On a multiprocessor machine, it should not matter which processor is called.
//However, you can get different results on different processors due to bugs in
//the BIOS or the HAL. To specify processor affinity for a thread, use the SetThreadAffinityMask function.
HANDLE hThread=GetCurrentThread();
SetThreadAffinityMask(hThread,0x1);
//主板上高精度定时器的晶振频率
//这个定时器应该就是一片8253或者8254
//在intel ich7中集成了8254
LARGE_INTEGER lFrequency;
QueryPerformanceFrequency(&lFrequency);
//printf("高精度定时器的晶振频率:%1.0fHz.\n",(double)lFrequency.QuadPart);
//这个定时器每经过一个时钟周期,其计数器会+1
LARGE_INTEGER lPerformanceCount_Start;
QueryPerformanceCounter(&lPerformanceCount_Start);
//RDTSC指令:获取CPU经历的时钟周期数
__int64 _i64StartCpuCounter=RDTSC();
//延时长一点,误差会小一点
//int nTemp=100000;
//while (--nTemp);
Sleep(200);
LARGE_INTEGER lPerformanceCount_End;
QueryPerformanceCounter(&lPerformanceCount_End);
__int64 _i64EndCpuCounter=RDTSC();
//f=1/T => f=计数次数/(计数次数*T)
//这里的“计数次数*T”就是时间差
double fTime=((double)lPerformanceCount_End.QuadPart-(double)lPerformanceCount_Start.QuadPart)
/(double)lFrequency.QuadPart;
return (_i64EndCpuCounter-_i64StartCpuCounter)/fTime;
}
int main(int argc, char* argv[])
{
printf("CPU频率为:%1.6fMHz.\n",CpuFrequency()/1000000.0);
return 0;
}
- QueryPerformanceFrequency,RDTSC,CPU频率
- QueryPerformanceFrequency,RDTSC,CPU频率
- QueryPerformanceFrequency,RDTSC,CPU频率
- rdtsc 指令测试 cpu 频率
- 关于RDTSC和CPU调频
- CPU频率
- CPU 频率
- rdtsc
- RDTSC
- QueryPerformanceFrequency
- QueryPerformanceFrequency
- QueryPerformanceFrequency
- QueryPerformanceFrequency
- QueryPerformanceFrequency
- QueryPerformanceFrequency
- QueryPerformanceFrequency()
- CPU的时钟频率
- 关于cpu的频率
- ACE线程管理---ACE_Thread_Manager
- Linux服务器:Linux中VMware虚拟机硬盘空间扩大方法
- 推荐:几款优秀的开源数据挖掘工具
- 纳什均衡
- Android 2.3 Gallery3D添加gif支持——修改代码(三)
- QueryPerformanceFrequency,RDTSC,CPU频率
- Android驱动
- Debian Linux 6 Squeeze: Install Linux Kernel 3.2.xx
- gcc4.8.0源代码安装
- 插入排序算法
- ArcGIS 10 SP5 (Desktop, Engine, Server)中文版 补丁
- WIN7的CMD界面下输入ipconfig后提示不是内部或外外部命令,也不是可运行的程序或批处理文件
- 强力推荐几种多媒体播放器方案(jQuery、Flash、HTML5)
- Settings.Global