CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

如何在windows下面实现小于1毫秒的精确计时

楼主tangwp(tangwp)2002-05-24 15:14:17 在 VC/MFC / 基础类 提问

如何在windows下面实现小于1毫秒的精确计时?请指教 问题点数:50、回复次数:6Top

1 楼z_sky()回复于 2002-05-24 15:56:15 得分 10

Multimedia   Timer   Functions  
  The   following   functions   are   used   with   multimedia   timers.  
     
  timeBeginPeriod      
  timeEndPeriod      
  timeGetDevCaps      
  timeGetSystemTime      
  timeGetTime      
  timeKillEvent      
  TimeProc      
  timeSetEvent      
   
  check   them   with   MSDNTop

2 楼masterz(www.fruitfruit.com)回复于 2002-05-24 16:41:07 得分 10

__int64   RDTSC()  
   
  {  
   
  unsigned   int   lopart,   hipart;  
   
  __asm  
   
  {  
   
  rdtsc  
   
  mov   lopart,   eax  
   
  mov   hipart,   edx  
   
  }  
   
  return   lopart   +   (hipart*(4294967296UL));  
   
  }  
  Top

3 楼dylanwolf()回复于 2002-05-24 16:48:51 得分 10

Use   this   two   functions,   can   achieve   微秒级别  
   
   
  QueryPerformanceCounter  
  The   QueryPerformanceCounter   function   retrieves   the   current   value   of   the   high-resolution   performance   counter,   if   one   exists.    
   
  QueryPerformanceFrequency  
  The   QueryPerformanceFrequency   function   retrieves   the   frequency   of   the   high-resolution   performance   counter,   if   one   exists.    
   
  BOOL   QueryPerformanceFrequency(  
      LARGE_INTEGER   *lpFrequency       //   address   of   current   frequency  
  );  
     
  Parameters  
  lpFrequency    
  Pointer   to   a   variable   that   the   function   sets,   in   counts   per   second,   to   the   current   performance-counter   frequency.   If   the   installed   hardware   does   not   support   a   high-resolution   performance   counter,   this   parameter   can   be   to   zero.    
   
   
  BOOL   QueryPerformanceCounter(  
      LARGE_INTEGER   *lpPerformanceCount       //   pointer   to   counter   value  
  );  
     
  Parameters  
  lpPerformanceCount    
  Pointer   to   a   variable   that   the   function   sets,   in   counts,   to   the   current   performance-counter   value.   If   the   installed   hardware   does   not   support   a   high-resolution   performance   counter,   this   parameter   can   be   to   zero.    
  Top

4 楼winne_ll(feiyang)回复于 2002-05-24 16:54:36 得分 20

可以精确到0.000001秒  
   
  看看下面的代码,你在VC里运行试试:)  
   
  #include   "stdafx.h"  
  #include   "windows.h"  
  int   main(int   argc,   char*   argv[])  
  {  
  LARGE_INTEGER   countstart;  
  LARGE_INTEGER   countend;  
  __int64   timediff;  
  LARGE_INTEGER   frequent;  
  QueryPerformanceCounter(   &countstart);  
  printf("Hello   World!\n");  
  printf("Hello   World!\n");  
  printf("Hello   World!\n");  
  QueryPerformanceCounter(   &countend);  
  timediff   =   (__int64)countend.QuadPart-(__int64)countstart.QuadPart;  
  QueryPerformanceFrequency(&frequent);  
  double   dsec   =   (double)timediff/(double)frequent.QuadPart;  
  printf("elapsed   time   :%f(second)\n",dsec);  
  return   0;  
  }  
  也可以用下面的  
      可以使用多媒体定时器啊,函数如下:  
  1。QueryPerformanceFrequency,取得你的系统支持的定时器的频率  
  2。QueryPerformanceCounter   ,计算走过的时间用,这个时间指的是系统启动后经历的时间,你自己程序的时间要用减法来算。Top

5 楼1980xls(狮子山人)回复于 2002-05-24 19:57:44 得分 0

getthinckcount()Top

6 楼programcat2001(旧游以梦)回复于 2002-05-24 19:58:53 得分 0

用工业计时器Top

相关问题

  • 可以设置小于1毫秒的延时吗,教教我
  • 如何在UNIX下用C实现精确到毫秒计时?
  • 请问如何做一个计时器,并且能精确到毫秒级?
  • 求VB下能精确计时到毫秒的函数或程序
  • 寻找关于准确计时的函数!要求精确到毫秒
  • 挑战高手的问题啊,怎样使TIMER时间间隔小于1毫秒
  • 在Windows 9x 及 2000/NT 下如何达到微秒级的计时?
  • 怎么计时?
  • 精确计时?
  • 计时器

关键词

  • hipart
  • lopart
  • queryperformancefrequency
  • 时间
  • function

得分解答快速导航

  • 帖主:tangwp
  • z_sky
  • masterz
  • dylanwolf
  • winne_ll

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

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