C# 用法:

    public static class QueryPerformanceMethd
{
[DllImport("kernel32.dll")]
public extern static short QueryPerformanceCounter(ref long x); [DllImport("kernel32.dll")]
public extern static short QueryPerformanceFrequency(ref long x);
}
    static void Main(string[] args)
{
long stop_Value = 0;
long start_Value = 0;
long freq = 0; QueryPerformanceMethd.QueryPerformanceFrequency(ref freq);
QueryPerformanceMethd.QueryPerformanceCounter(ref start_Value);
//Fun() 需要计时方法
QueryPerformanceMethd.QueryPerformanceCounter(ref stop_Value);
double time = (double)(stop_Value - start_Value) / (double)(freq); Console.WriteLine(time);//单位S
Console.ReadLine();
}

计算所得time即为fun()方法所消耗时间。

C++中QueryPerformanceCounter  QueryPerformanceFrequency的用法

#include "stdafx.h"
#include "windows.h" void main()
{
LARGE_INTEGER nFreq;
LARGE_INTEGER nBeginTime;
LARGE_INTEGER nEndTime;
double time;
QueryPerformanceFrequency(&nFreq);
QueryPerformanceCounter(&nBeginTime);
Sleep();
QueryPerformanceCounter(&nEndTime);
time = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) / (double)nFreq.QuadPart;
printf("%f\n", time);
system("Pause");
}

计算Sleep(1000)所消耗的精确时间,并非精确的1s

最新文章

  1. CSS属性小结之--半透明处理
  2. FineReport层式报表解决大数据集展示问题攻略
  3. 【快报】基于K2 BPM的新一代协同办公门户实践交流会
  4. http协议本身能获取客户端Mac地址问题
  5. PHP 提取图片img标记中的任意属性
  6. bzoj2743
  7. FANTASY:In which way do you think the world will end?
  8. LVS集群TUN模式实例(5)
  9. 从 0 到 1 实现 React 系列 —— 5.PureComponent 实现 && HOC 探幽
  10. 关于使用Visual编译静态库动态库及其使用的问题
  11. wcf事务
  12. 卸载CentOS7自带的OpenJDK
  13. PAT——1059. C语言竞赛
  14. flex布局语法(阮一峰)
  15. 灵活的javaScript
  16. VueJS开发所用到的技术栈
  17. 算法练习5---快速排序Java版
  18. ssh以bash登录的配置
  19. Git/GitHub仓库管理常用的3条命令
  20. Linux环境安装Nginx详细步骤

热门文章

  1. quarz入门案例
  2. linux的netstat命令详解
  3. ThinkPHP5如何引用新建的配置文件?
  4. ORA-01940:无法删除当前已链接的用户
  5. Hadoop之HDFS(二)HDFS基本原理
  6. elasticsearch2.x插件之一:kopf
  7. 【bzoj1602】[Usaco2008 Oct]牧场行走
  8. Linux 安装lamp
  9. 今天写shader流光效果,shader代码少了个括号,unity shader compiler卡死且不提示原因
  10. 2-配置Andriod环境时的错误。。。Theme.AppCompat.Light