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=

随便看看

vs下调试程序时,把信息打印到输出窗口

重印:https://blog.csdn.net/cwj066/article/details/82423627 https://stackoverflow.com/questions/20508086/getting-rid-of-atltracegeneral-category-shown-in-atltrace-output方法1:编写一个变量参数函数...

Hibernate 数据的批量插入、更新和删除

对于这个批处理场景,Hibernate提供了一个批处理解决方案。接下来,我们将从批插入、批更新和批删除三个方面介绍如何处理此批处理场景。为了避免这种情况,Hibernate为批量更新和批量删除提供了类似于SQL的HQL语法。...

docker安装宝塔

主机的/home/www文件夹映射到docker容器的/www(注意:如果文件目录不存在,特权意味着在运行容器时,容器被授予特权,容器有权写入文件。然后问题来了……安装完成后,如果重新启动容器,容器宝塔会丢失吗?不,让我们试试:...

关于利用RD client远程电脑,和输入法的一些问题

我在寝室,利用转接头,借助手机app“RDclient”成功完成在键盘上输入文字,并在电脑上输出内容。“RDclient”可以完成手机端远程连接电脑端,只需要知道电脑的ip,用户名和密码就可以。“RDclient”这是微软自家发布的软件,还是很不错的。不过,在刚开始连接的时候,输入法遇到一点问题。后来,在手机上,调出输入法打字的界面,更换成英文输入模式,然后...

IntelliJ IDEA(2017)安装和破解

IDEA全称IntelliJIDEA,是Java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一,尤其在智能代码助手、代码自动提示、重构、J2EE支持、各类版本工具、JUnit、CVS整合、代码分析、创新的GUI设计等方面的功能可以说是超常的。用记事本打开分别在最下面一行增加一行:-javaagent:D:IDEAinJetbra...

Matlab高级教程_第二篇:Matlab相见恨晚的模块_02_并行运算-1

3 MATLAB2009之后,并行计算工具箱和并行计算服务退出。通过PCT和DCS,用户可以实现基于多核平台、多处理器平台和集群平台的多个并行计算任务。除了支持上述通用功能外,PCT还增加了对GPU单元的支持。现在来看彼此已经太晚了:用parfor并行化for循环。在编程中,使计算量最小化的代码总是一个循环。7 parpool命令在不启动并行池的情况下配置并...