CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

如何取到CPU的频率

楼主Jestic(Jestic)2003-11-04 09:59:06 在 Delphi / VCL组件开发及应用 提问

请指教 问题点数:20、回复次数:1Top

1 楼crossbow(【以无形为形】)回复于 2003-11-04 10:20:39 得分 20

这个问题怎么没有人答?我来吧:  
  function   GetCPUSpeed:   Double;    
  const  
   
  DelayTime   =   500;  
   
  var  
   
  TimerHi,   TimerLo:   DWORD;  
   
  PriorityClass,   Priority:   Integer;  
   
  begin  
   
  try  
   
  PriorityClass   :=   GetPriorityClass(GetCurrentProcess);  
   
  Priority   :=   GetThreadPriority(GetCurrentThread);  
   
  SetPriorityClass(GetCurrentProcess,   REALTIME_PRIORITY_CLASS);  
   
  SetThreadPriority(GetCurrentThread,THREAD_PRIORITY_TIME_CRITICAL);  
   
  Sleep(10);  
   
  asm  
   
  dw   310Fh   //   rdtsc  
   
  mov   TimerLo,   eax  
   
  mov   TimerHi,   edx  
   
  end;  
   
  Sleep(DelayTime);  
   
  asm  
   
  dw   310Fh   //   rdtsc  
   
  sub   eax,   TimerLo  
   
  sbb   edx,   TimerHi  
   
  mov   TimerLo,   eax  
   
  mov   TimerHi,   edx  
   
  end;  
   
  SetThreadPriority(GetCurrentThread,   Priority);  
   
  SetPriorityClass(GetCurrentProcess,   PriorityClass);  
   
  Result   :=   TimerLo   /   (1000.0   *   DelayTime);  
   
  except  
   
  Result   :=   0;  
   
  end;  
   
  end;  
   
  *************  
   
  在VC中用以下代码可以测出CPU的主频:  
   
  static   int   time[2]  
   
  int   cpuclock;  
   
  在InitInstance中  
   
  SetTimer(hWnd,1,1000,NULL)  
   
  在消息处理过程中  
   
  case   WM_CREATE;  
   
  _asm{  
   
  rdtsc   //一个64bit的时间标记计数器  
   
  mov   ecx,offset   time  
   
  mov   [ecx+0],edx  
   
  mov   [ecx+4],eax  
   
  }  
   
  break;  
   
  case   WM_TIMER:  
   
  _asm  
   
  {  
   
  rdtsc  
   
  mov   ebx,offset   time  
   
  sub   eax,[ebx+4]  
   
  sbb   edx,[ebx+0]  
   
  mov   ecx,1000000  
   
  div   ecx  
   
  mov   cpuclock,eax  
   
  }  
   
  但不知在DELPHI中如何编程测试?还有CPU的类型等等!  
   
     
   
  --------------------------------------------------------------------------------  
   
  来自:cat.yy   时间:00-12-29   16:17:03   ID:427844  
   
  SetTimer(handle,1,1000,NULL);  
   
  ...  
   
  ...(var   msg:   message)...  
   
  if   msg.message=WM_CREATE   then  
   
  begin  
   
  asm  
   
  rdtsc   //一个64bit的时间标记计数器  
   
  mov   ecx,offset   time  
   
  mov   [ecx+0],edx  
   
  mov   [ecx+4],eax  
   
  end;  
   
  end;  
   
  if   msg.message=WM_TIMER   then  
   
  begin  
   
  asm  
   
  rdtsc  
   
  mov   ebx,offset   time  
   
  sub   eax,[ebx+4]  
   
  sbb   edx,[ebx+0]  
   
  mov   ecx,1000000  
   
  div   ecx  
   
  mov   cpuclock,eax  
   
  end;  
   
  end;  
   
  *************  
   
  function   TForm1.GetCpuSpeed:   Extended;  
   
  var  
   
  t,   mhi,   mlo,   nhi,   nlo:   dword;  
   
  shr32   :   comp;  
   
  begin  
   
  shr32   :=   65536;  
   
  shr32   :=   shr32   *   65536;  
   
  t   :=   GetTickCount;  
   
  while   t   =   GetTickCount   do   ;  
   
  asm  
   
  DB   0FH,031H   //   rdtsc  
   
  mov   mhi,edx  
   
  mov   mlo,eax  
   
  end;  
   
  while   GetTickCount   <   (t   +   1000)   do   ;  
   
  asm  
   
  DB   0FH,031H   //   rdtsc  
   
  mov   nhi,edx  
   
  mov   nlo,eax  
   
  end;  
   
  Result   :=   ((nhi   *   shr32   +   nlo)   -   (mhi   *   shr32   +   mlo))   /   1E6;  
   
  end;Top

相关问题

  • 如何测定CPU的这是频率
  • 如何获取Windows的版本号和build Number还有CPU的频率,型号?
  • pb如何获取当前系统的CPU频率及内存总量??
  • WINXP/2K下如何读取,硬盘,内存大小,如何得到CPU 工作频率。
  • 用纯Java如何获得本机CPU的频率?多谢了...
  • 求助:如何得到CPU的原始时钟频率?
  • 有关如何得到CPU频率的问题。
  • 如何得到硬件信息,如内存大小,cpu频率,硬盘大小
  • 如何计算cpu的使用频率?使用什么api,还是其他东西?
  • 有谁知道如何获得CPU 1秒的时钟周期数(就是工作频率,也叫主频)

关键词

  • 64bit
  • cpu
  • timerlo
  • eaxend
  • getcurrentthread
  • shr32
  • priority
  • getcurrentprocess
  • gettickcount
  • fh

得分解答快速导航

  • 帖主:Jestic
  • crossbow

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo