执行 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 (intchar**)
{
   
 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(&lt); 
    //total_counter += lt.wMilliseconds;
    
    // total_counter += _time32(NULL);   time(NULL)
   
     GetSystemTimeAsFileTime(&SystemTimeAsFileTime);
     FileTimeToSystemTime(&SystemTimeAsFileTime,&lt);
     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;
}
 
 转自:http://gmd20.blog.163.com/blog/static/168439232012113111759514/

(转)windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime的更多相关文章

  1. windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime

    http://gmd20.blog.163.com/blog/static/168439232012113111759514/ 执行 10000000 次, 耗时 2258,369 微秒     Qu ...

  2. Windows 各种计时函数总结(QueryPerformanceCounter可以达到微秒)

    本文对Windows平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的5种方法.分为在标准C/C++下的二种time()及clock(),标准C/C++所以使用的time()及clock ...

  3. Windows获取时间函数(使用GetLocalTime,GetSystemTime,SystemTimeToTzSpecificLocalTime,GetFileTime API函数

    获取本地时间 typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; ...

  4. windows时间函数

    介绍        我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执 行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如我们通过记 ...

  5. Windows 各种计时函数总结

    本文对Windows平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的 5种方法.分为在标准C/C++下的二种time()及clock(),标准C/C++所以使用的time()及cloc ...

  6. <转>Windows 各种计时函数总结

    本文转自MoreWindows 特此标识感谢 http://blog.csdn.net/morewindows/article/details/6854764 本文对Windows平台下常用的计时函数 ...

  7. C++程序在Windows平台上各种定位内存泄漏的方法,并对比了它们的优缺点

    一.前言 在Linux平台上有valgrind可以非常方便的帮助我们定位内存泄漏,因为Linux在开发领域的使用场景大多是跑服务器,再加上它的开源属性,相对而言,处理问题容易形成“统一”的标准.而在W ...

  8. Windows平台分布式架构实践 - 负载均衡

    概述 最近.NET的世界开始闹腾了,微软官方终于加入到了对.NET跨平台的支持,并且在不久的将来,我们在VS里面写的代码可能就可以通过Mono直接在Linux和Mac上运行.那么大家(开发者和企业)为 ...

  9. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

随机推荐

  1. [转载]Class-AB Amplifier 笔记

    Class-AB Amplifier 笔记 Reading Notes from Mikko Loikkanen “Design and Compensation of High Performanc ...

  2. js 去掉前后空格

    前后去空格 return str.replace(/(^\s*)|(\s*$)/g, ""); 全部去空格 $("#panelbody").text().rep ...

  3. Android利用Fiddler进行网络数据抓包【怎么跟踪微信请求】

    主要介绍Android及IPhone手机上如何利用Fiddler进行网络数据抓包,比如我们想抓某个应用(微博.微信.墨迹天气)的网络通信请求就可以利用这个方法. Mac 下请使用 Charles 代替 ...

  4. Hadoop: Setup Maven project for MapReduce in 5mn

    Hadoop: Setup Maven project for MapReduce in 5mn 25 MAY 2013 / ANTOINE AMEND I am sure I am not the ...

  5. Android设计中的.9.png图片

    .9.png是一种能够自己定义拉伸特定区域的图片格式. 简书:Android设计中的.9.png图片 在Android的UI设计开发中,非常多控件须要适配不同的手机分辨率进行拉伸或者压缩,这样就出现了 ...

  6. Django内置过滤器详解附代码附效果图--附全部内置过滤器帮助文档

    前言 基本环境 Django版本:1.11.8 Python版本:3.6 OS: win10 x64 本文摘要 提供了常用的Django内置过滤器的详细介绍,包括过滤器的功能.语法.代码和效果示例. ...

  7. 移动端自动化测试 -- appium 之Desired Capabilities与 定位控件

    一.Desired Capabilities Desired Capabilities 在启动 session 的时候是必须提供的. Desired Capabilities 本质上是以 key va ...

  8. 每日英语:China Poses Challenge for Coal

    China's appetite for coal, once seemingly unlimited, is starting to wane, and the effects are rippli ...

  9. 深入理解Eureka - Eureka配置列表

    Eureka包含四个部分的配置 instance:当前Eureka Instance实例信息配置 client:Eureka Client客户端特性配置 server:Eureka Server注册中 ...

  10. html5和css3学习历程

    1.video,audio视频和音频的应用 <!doctype html><html> <head></head> <body>  < ...