GetTickCount() 函数的作用和用法

摘要:
返回值指示毫秒数。返回值:如果正确,则返回毫秒数。标题:Winbase。h、 链接库:Coredll。库。2) 用于计算操作的时间:Start:=GetTickCount//执行耗时的操作Stop:=GetTikCount;使用时间:=/1000;//Xxx秒用于计时:voidmain(){DWORDdwLast;DWORDdwCurrent;DWORDdwInterval=1000;dwLast=GetTickCount();int i=0;而{dwCurrent=GetTickCount*();ifcontinue;//yourcodetobe executedwhenIntervalselapsedprintf;//yourcodetodeterminehentobreakifbreak;i++;dwLast=dwCurrent;printf(“Timeup!”);中断;}getchar();return;}对于一般的实时控制,GetTickCount()函数可以满足精度要求,但为了进一步提高计时精度,应使用QueryPerformanceFrequency()函数和QueryPerformanceCounter()函数。这两个函数都是VC仅为Windows9X 9X提供的高精度时间函数,需要计算机从硬件上支持高精度计时器。

原文:http://www.cnblogs.com/jxsoft/archive/2011/10/17/2215366.html

DWORD GetTickCount(void);    

1) 定义

For Release configurations, this function returns the number of milliseconds since the device booted, excluding any time that the system was suspended. GetTickCount starts at 0 on boot and then counts up from there.

在Release版本中,该函数从0开始计时,返回自设备启动后的毫秒数(不含系统暂停时间)。

For Debug configurations, 180 seconds is subtracted from the the number of milliseconds since the device booted. This allows code that uses GetTickCount to be easily tested for correct overflow handling.

在Debug版本中,设备启动后便从计时器中减去180秒。这样方便测试使用该函数的代码的正确溢出处理。

Return Values

The number of milliseconds indicates success.

返回值:如正确,返回毫秒数。

Header: Winbase.h.
Link Library: Coredll.lib.

2) 应用

用来计算某个操作所使用的时间:   

GetTickCount() 函数的作用和用法第1张  Start:=GetTickCount;   
GetTickCount() 函数的作用和用法第1张   ...//执行耗时的操作   
GetTickCount() 函数的作用和用法第1张   Stop:=GetTickCount;   
GetTickCount() 函数的作用和用法第1张   TimeUsed:=(Stop-Start)/1000;     //使用了xxx秒

用来定时:  

GetTickCount() 函数的作用和用法第1张
GetTickCount() 函数的作用和用法第1张void main() 
GetTickCount() 函数的作用和用法第7张{
GetTickCount() 函数的作用和用法第8张  DWORD dwLast;
GetTickCount() 函数的作用和用法第8张  DWORD dwCurrent;
GetTickCount() 函数的作用和用法第8张  DWORD dwInterval = 1000;
GetTickCount() 函数的作用和用法第8张  dwLast = GetTickCount();
GetTickCount() 函数的作用和用法第8张  int i = 0;
GetTickCount() 函数的作用和用法第8张  while(true)
GetTickCount() 函数的作用和用法第14张     {
GetTickCount() 函数的作用和用法第8张        dwCurrent = GetTickCount();
GetTickCount() 函数的作用和用法第8张        if( dwCurrent - dwLast < dwInterval )
GetTickCount() 函数的作用和用法第8张        continue;
GetTickCount() 函数的作用和用法第8张         //your code to be executed when interval is elapsed
GetTickCount() 函数的作用和用法第8张        printf("dwLast,dwCurrent,diff:%d,%d,%d ",dwLast,dwCurrent,dwCurrent-dwLast);
GetTickCount() 函数的作用和用法第8张         //your code to determine when to break
GetTickCount() 函数的作用和用法第8张        if( i > 10 ) break;
GetTickCount() 函数的作用和用法第8张        i++;
GetTickCount() 函数的作用和用法第8张        dwLast = dwCurrent;
GetTickCount() 函数的作用和用法第8张        printf("Time is up!");
GetTickCount() 函数的作用和用法第8张        break;
GetTickCount() 函数的作用和用法第26张     }
GetTickCount() 函数的作用和用法第8张   getchar();   
GetTickCount() 函数的作用和用法第8张   return;
GetTickCount() 函数的作用和用法第29张

对于一般的实时控制,使用GetTickCount()函数就可以满足精度要求,但要进一步提高计时精度,就要采用QueryPerformanceFrequency()函数和QueryPerformanceCounter()函数。这两个函数是VC提供的仅供Windows   9X使用的高精度时间函数,并要求计算机从硬件上支持高精度计时器。

以上引用:

http://www.wesoho.com/article.asp?id=2072

http://bitboy.blog.edu.cn/user1/19986/archives/2005/1001846.shtml

免责声明:文章转载自《GetTickCount() 函数的作用和用法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇微服务架构设计如何打开dwg文件下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

pl/sql中的取模运算

pl/sql语言的取模(即求余)运算不使用大部分语言所支持的a%b而是使用函数mod(a,b)例子如下:写一个匿名块判断某年是否是闰年,能被4但是不能被100整除,或者能被400整除1declare2judgevarchar2(200);3year_inputnumber;4begin5year_input:='&输入年份';6if(mod(year...

Visual Studio Code 之 运行java代码

2、安装成功后,会在右键菜单中多出一个选项:更改vscode“用户设置”文件:添加java.home以及runcode显示在终端coderunner原生的配置有些问题,更改其中终端的命令:加入红色的部分3、点击RunCode,会执行相应的文件...

Jmeter中获取返回结果中的值

在jmeter的测试中,通常需要在下一个请求中使用上一个请求的返回值。如何获得返回值非常重要。插件下载地址为:http://jmeter-plugins.org/wiki/JSONPathExtractor/下载后,将lib文件夹放在jmeter目录中。...

注册支付宝沙箱并测试支付宝扫码连接

2.创建新的支付宝应用程序2.1下载支付宝生成软件密钥#访问“支付宝开发平台”登录并访问开发者中心https://open.alipay.com/platform/home.htm#您可以参考“计算机网站支付”来熟悉计算机支付的整个流程https://docs.open.alipay.com/270/105899/2.1步骤1:创建应用程序(此处使用沙盒环境...

《学习opencv》笔记——矩阵和图像操作——cvAnd、cvAndS、cvAvg and cvAvgSdv

矩阵和图像的操作cvAnd函数其结构voidcvAnd;程序实例#include#include#includeintmain{IplImage*src1,*src2,*src3;src1=cvLoadImage;src2=cvLoadImage;src3=cvLoadImage;cvAnd;cvShowImage;cvShowImage;cvShowIma...

安装samba服务器实现Linux mint和Windows共享文件

安装samba服务器以实现Linuxmint和Windows共享文件。在Linuxmint普通用户下执行命令:sudoapt-geinstallsamba、installsamba和打开smb。conf配置文件,并执行命令gedit/etc/samba/smb-Coff,如果您想安装gedit(sudoapt-geinstallgedit),还可以使用Lin...