Windows下时间测试函数
来源:互联网 发布:李华清经济学考研知乎 编辑:程序博客网 时间:2024/05/21 15:49
Windows提供了如下的高精度性能函数:
BOOL QueryPerformanceFrequency(LARGE_INTEGER* pliFrequency);
BOOL QueryPerformanceCounter(LARGER_INTEGER* pliCount);
这些函数假设正在执行的线程不会被抢占,但是大多数高精度性能分析都是针对生命期限很短的代码块。可以使用下面的封装C++类来测试时间:
// QueryPerformance.h#ifndef _QUERY_PERFORMANCE_H#define _QUERY_PERFORMANCE_H#include <Windows.h>class CStopwatch{public:CStopwatch();void Start();__int64 Now() const;__int64 NowInMicro() const;private:LARGE_INTEGER m_liPerfFreq; // Counts per secondLARGE_INTEGER m_liPerfStart; // starting count};#endif
// QueryPerformance.cpp#include "QueryPerformance.h" CStopwatch::CStopwatch(){QueryPerformanceFrequency(&m_liPerfFreq);Start();}void CStopwatch::Start(){QueryPerformanceCounter(&m_liPerfStart);} __int64 CStopwatch::Now() const{LARGE_INTEGER liPerfNow;QueryPerformanceCounter(&liPerfNow);return (((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000) / m_liPerfFreq.QuadPart);} __int64 CStopwatch::NowInMicro() const{LARGE_INTEGER liPerfNow;QueryPerformanceCounter(&liPerfNow);return (((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000000) / m_liPerfFreq.QuadPart);}
使用方法:
// 创建一个计时器对象 -- stopwatch (默认为当前的时间)
CStopwatch stopwatch;
// 需要测试的代码
...........
...........
...........
// 获取到现在消耗的时间
__int64 qwElapsedTime = stopwatch.Now(); // 单位为:毫秒(ms)
0 0
- Windows下时间测试函数
- Windows下利用c语言测试函数运行时间
- windows 下获取时间函数
- Windows下时间函数总结
- 关于windows下的时间函数
- windows下统计时间的函数
- 使用QT在windows下高精度测试程序运行时间
- 时间测试函数
- C++ 测试时间函数
- CPU时间测试函数
- 测试函数运行时间
- 测试函数运行时间
- Windows系统下获取一段函数执行的时间
- Windows/Linux下C/C++时间函数全攻略
- 扩展windows下julia语言的时间串处理函数
- Windows时间函数大全
- Windows时间函数大全
- Windows时间函数大全
- Halcon程序
- 第六章 知识结构导图
- linux下python安装pylib
- QML与C++混合编程详解
- 数据库的基本操作
- Windows下时间测试函数
- MFC ODBC数据库操作编程
- 深入分析Intent匹配查询
- 经典问题-生产者和消费者问题
- Bootstrap 文件上传插件Filestyle的用法
- [leetcode 94] Binary Tree Inorder Traversal
- 1028. 人口普查(20)
- 如何查看mac笔记本是64位还是32为
- Unity学习之GUI基础