(转)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++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...
随机推荐
- 在CentOS 7上安装Node.js的4种方法(yum安装和源码安装)
CentOS 7上的安装方法,其中涵盖了源码安装,已编译版本安装,EPEL(Extra Packages for Enterprise Linux)安装和通过NVM(Node version mana ...
- java Web服务实现方案(REST+SOAP+XML-RPC)简述及比较
目前知道的三种主流的Web服务实现方案为:REST:表象化状态转变 (软件架构风格)SOAP:简单对象访问协议 XML-RPC:远程过程调用协议 下面分别作简单介绍: REST:表征状态转移(Repr ...
- Oracle学习笔记之五sp1,PL/SQL之BULK COLLECT
Bulk Collect特性可以让我们在PL/SQL中能使用批查询,批查询在某些情况下能显著提高查询效率. BULK COLLECT 子句会批量检索结果,即一次性将结果集绑定到一个集合变量中,并从SQ ...
- ev3dev :利用ssh登录系统
ev3dev是在debian 8 的基础上修改的,主页上只介绍了利用usb连接系统后,ssh登录的方法. 可是我想用wifi连接到网络后,用ssh登录,非usb线连接. ev3dev的默认用户名为:r ...
- Nginx用户认证配置方法详解(域名/目录)
Nginx超级强大它可以单独为一个域名设置用户认证,方法也很简单我们只要生成用户认证的用户名和密码,然后再Nginx添加auth认证配置即可 Nginx可以为某一个域名单独加用户认证,具体做法如下: ...
- Hbase shell 常用命令(1)
下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如下: 名称 命令表达式 创建表 create '表名称', '列名称1','列名称2','列名称N ...
- XPath Cookbook-Axes(轴)
http://blog.csdn.net/duruiqi_fx/article/details/55511164 ******************************************* ...
- const在c和c++中地位不同
先测试C语言的const: #include<stdio.h> int main() { ; //等价于 //int const a = 10; //a = 11;//err ; cons ...
- iOS菊花加载圈
自定制一个继承于UIView的类然后重写initWithFrame方法;如下 - (id)initWithFrame:(CGRect)frame { self = [super initWithFra ...
- C++14尝鲜:Generic Lambdas(泛型lambda)
所谓泛型lambda.就是在形參声明中使用auto类型指示说明符的lambda. 比方 auto lambda = [](auto x, auto y) {return x + y;}; 依据C++1 ...