(转)windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime
执行 10000000 次, 耗时 2258,369 微秒 QueryPerformanceCounter
执行 10000000 次, 耗时 26,347 微秒 GetTickCount
执行 10000000 次, 耗时 242,879 微秒 time()
c的时间函数 time(time_t) 大概比GetSystemTimeAsFileTime慢6倍,比_ftime 快6倍
执行 10000000 次, 耗时 1310,066 微秒 _ftime
执行 10000000 次, 耗时 1722,125 微秒 GetLocalTime
执行 10000000 次, 耗时 39,131 微秒 GetSystemTimeAsFileTime
GetLocalTime耗时等于 = GetSystemTimeAsFileTime 耗时+ FileTimeToSystemTime 的耗时
------------
可以看到精度越高性能越差
GetTickCount 精度1毫秒 > GetLocalTime 精度100纳秒 (0.1 微秒) > QueryPerformanceCounter (搞不懂这个怎么这么差)
如果仅仅为了计算时间偏差,可以使用 GetSystemTimeAsFileTime,这个精度可以达到100纳秒,
msdn有个介绍。
http://msdn.microsoft.com/ZH-CN/library/windows/desktop/ms724284(v=vs.85).aspx
Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should copy the low- and high-order parts of the file time to a ULARGE_INTEGER structure, perform 64-bit arithmetic on the QuadPart member, and copy the LowPart and HighPart members into the FILETIME structure.
Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows.
测试代码如下
#include <iomanip>#include <fstream>#include <iostream>#include <map>#include <sstream>#include <list>#include <vector> #include <stdlib.h>#include <stdint.h>#include <stdio.h>#include <sys/types.h>#include <sys/timeb.h>#include <time.h>#include <Windows.h> #include "Trace.h" using namespace std; int main (int, char**){ LARGE_INTEGER freq, t0, t1; QueryPerformanceFrequency(&freq); size_t number = 10000000; int total_counter = 0; //LARGE_INTEGER t3; //struct timeb timebuffer; SYSTEMTIME lt; FILETIME SystemTimeAsFileTime; QueryPerformanceCounter(&t0); for (int i=0; i< number; i++) { //QueryPerformanceCounter(&t3); //total_counter += t3.LowPart; //total_counter += GetTickCount(); //ftime(&timebuffer); //total_counter += timebuffer.time; //GetLocalTime(<); //total_counter += lt.wMilliseconds; // total_counter += _time32(NULL); time(NULL) GetSystemTimeAsFileTime(&SystemTimeAsFileTime); FileTimeToSystemTime(&SystemTimeAsFileTime,<); total_counter += lt.wMilliseconds; } QueryPerformanceCounter(&t1); int time = (((t1.QuadPart-t0.QuadPart)*1000000)/freq.QuadPart); std::cout << "执行 " << number <<" 次, 耗时 " << time << " 微秒" << std::endl; std::cout << total_counter; int a; cin >> a; return 0;}(转)windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime的更多相关文章
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime
http://gmd20.blog.163.com/blog/static/168439232012113111759514/ 执行 10000000 次, 耗时 2258,369 微秒 Qu ...
- Windows 各种计时函数总结(QueryPerformanceCounter可以达到微秒)
本文对Windows平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的5种方法.分为在标准C/C++下的二种time()及clock(),标准C/C++所以使用的time()及clock ...
- Windows获取时间函数(使用GetLocalTime,GetSystemTime,SystemTimeToTzSpecificLocalTime,GetFileTime API函数
获取本地时间 typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; ...
- windows时间函数
介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执 行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如我们通过记 ...
- Windows 各种计时函数总结
本文对Windows平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的 5种方法.分为在标准C/C++下的二种time()及clock(),标准C/C++所以使用的time()及cloc ...
- <转>Windows 各种计时函数总结
本文转自MoreWindows 特此标识感谢 http://blog.csdn.net/morewindows/article/details/6854764 本文对Windows平台下常用的计时函数 ...
- C++程序在Windows平台上各种定位内存泄漏的方法,并对比了它们的优缺点
一.前言 在Linux平台上有valgrind可以非常方便的帮助我们定位内存泄漏,因为Linux在开发领域的使用场景大多是跑服务器,再加上它的开源属性,相对而言,处理问题容易形成“统一”的标准.而在W ...
- Windows平台分布式架构实践 - 负载均衡
概述 最近.NET的世界开始闹腾了,微软官方终于加入到了对.NET跨平台的支持,并且在不久的将来,我们在VS里面写的代码可能就可以通过Mono直接在Linux和Mac上运行.那么大家(开发者和企业)为 ...
- C++中的时间函数
C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...
随机推荐
- Pandas dataframe 与 Spark dataframe 的区别
区别 :http://www.voidcn.com/article/p-wsqbotem-boa.html 获取列名的列表: DataFrame.columns.values.tolist()
- jenkins 发送邮件失败
jenkins 配置发送邮件,发送测试邮件,邮件发送失败: Failed to send out e-mail javax.mail.MessagingException: Could not con ...
- angular学习笔记(十)-src和href处理
本篇主要介绍angular中图片的src和链接的href的处理: 用到了以下两个属性: ng-src: 绑定了数据的路径表达式 ng-href: 绑定了数据的路径表达式 例如: <!DOCTYP ...
- ny714 Card Trick
Card Trick 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The magician shuffles a small pack of cards, holds ...
- NY891 区间选点 找点
找点 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 上数学课时,老师给了LYH一些闭区间,让他取尽量少的点,使得每个闭区间内至少有一个点.但是这几天LYH太忙了,你们帮 ...
- PairRDD中算子combineByKey图解
1.combineByKey combine 为结合意思. 作用: 将RDD[(K,V)] => RDD[(K,C)] 表示V的类型可以转成C两者可以不同类型. def combineBy ...
- 五、String在Java中是传“引用”
这个是Java的经典问题.许多类似的问题在stackoverflow被提问,有很多不正确或不完备的答案.如果不想太多你会认为这个问题比较简单.( The question is simple if y ...
- web.xml中init-param中的param-name
转载自:http://www.cnblogs.com/hzj-/articles/1689836.html <context-param>的作用:web.xml的配置中<contex ...
- tomcat8源码之架构解析
Catalina:与开始/关闭shell脚本交互的主类,因此如果要研究启动和关闭的过程,就从这个类开始看起. Server:是整个Tomcat组件的容器,包含一个或多个Service. Service ...
- JS自动爆炸案例
学习到了: setTimeout函数的灵活运用. 案例实现讲解: 1.先定义一个全局的变量,赋值为null. 2.然后使用timeout调用bang函数,以达到自动自动调用函数的功能. 3.bang函 ...