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=

随便看看

IOS崩溃日志解析(crash log)

IOS的应用程序少不了crash,互联网统计分析工具友盟有一项目错误分析的功能,专门用于应用程序崩溃日志统计,最近研究友盟上统计到的崩溃日志,在此对崩溃日志做一个简单的总结。否则,应用将被iOS终止,并产生低内存崩溃报告。这样,我们去我们的dSYM文件看看我们的UUID是否和崩溃日志上的UUID一致,只有dSYM文件的UUID和崩溃日志上的UUID一致,我们...

adb

ADB(AndroidDebugBridge)ANR(ApplicationNoResponding)ADB实际上是Android调试桥AndroidDebugBridge的缩写。adb是C/S体系结构的命令行工具。这里我们介绍一些常用的命令:adbdevices,获取设备列表和设备状态[xuxu:~]$adbdevicesList-devicesattac...

node 访问第三方API

如果没有提供头,将检测文件后缀,并在PUT请求中设置相应的内容类型。...

kafka数据迁移实践

每个代理都配置了两个数据磁盘。缓存数据分别存储在/data/kafka logs/和/data1/kafka logs/中。迁移后,重新启动kafka以生效。我们在kafka测试集群中原有的三个代理的基础上扩展了一个代理的容量。...

docker-compose启动容器后执行脚本或命令不退出 | 运行内部程序

好在,docker还有个特别之处,我们可以通过dockerbuild读取到Dockerfile中的指令后,在构建新镜像再起容器的时候,可以直接执行脚本文件运行容器内部应用程序,同时不退出容器。在dockerbuild新镜像后,同样docker-composeup-d启动容器服务,查看容器状态docker-composeps,进入容器并查看进程:事实证明,确实...

实用小技巧:在键盘没有小键盘时怎么打开任务管理器

原创:转载请注明出处!我需要为我的工作买一个87键的机械键盘。当我打开任务管理器打开时,我经常使用Ctrl+Alt+;现在不行了。有几种方法可以打开任务管理器以查看当前任务状态:1.Ctrl+Alt+Delete,这与之前的Ctrl+Alt+Delete相同,效果相同;2.Ctrl+Shift+Esc也可以调出任务管理器;3.右键单击任务栏的空白区域,然后从...