C++高精度性能测试函数
来源:互联网 发布:sql developer配置错误 编辑:程序博客网 时间:2024/06/15 00:46
在实际software开发工作中,我们经常会测试某个module或者function的执行效率。或者是某个算法的时间复杂度(虽然时间复杂度一定程度上依赖于机器性能,但在同一台computer上,经过算法优化,可以测试其复杂度);这时候就需要精确获取时间,才可以准确的运行时间,下面的函数实现了精确计时,计时精度可以达到微秒级;可用于测试某个模块的效率!
//Purpose :this programme is designed for testing the performance of your code ,some function ect,//it can show the time of spending on your running on it . it is beneficial to improve your performance //of code// author :Jackery_shh// data: July 8th 2015#include<Windows.h>#include<iostream>#include<tchar.h>using namespace std;#define IN#ifdef _DEBUG #define _Trace_Size 500inline void FileTrace(IN LPCTSTR szFormat, ...){if (szFormat == NULL)return;TCHAR t_trace[_Trace_Size] = { _T('\0') };va_list vl = NULL;// 生成内容va_start(vl, szFormat);_vsntprintf_s(t_trace, _Trace_Size, _TRUNCATE, szFormat, vl);va_end(vl);OutputDebugString(t_trace);}#elseinline void FileTrace(IN LPCTSTR szFormat, ...){}#endifLARGE_INTEGER begin_time ,freq;int main(){LARGE_INTEGER begin_time ,freq;QueryPerformanceFrequency (&freq);QueryPerformanceCounter (&begin_time); //begin time for (long test0=0;test0<5000000;test0++) { test0=test0+1; }LARGE_INTEGER end_time0; QueryPerformanceCounter (&end_time0);//after runnin the 'for' loop statement,the time is Time0 double Time0 = ((double) (end_time0.QuadPart - begin_time.QuadPart)*1000.0) / (double) (freq.QuadPart); int test1=10000;while (test1){test1--;} LARGE_INTEGER end_time1; QueryPerformanceCounter (&end_time1); double Time1 = ((double) (end_time1.QuadPart - begin_time.QuadPart)*1000.0) / (double) (freq.QuadPart); FileTrace(_T("*********************************************************************************\n"));FileTrace(_T("Test result is as follow :\ntime: %I64x, %.3fms, %.3fms\n"), (ULONGLONG)0, Time0, Time1);FileTrace(_T("*********************************************************************************\n")); system("pause");return 0;}test result is :
3 0
- C++高精度性能测试函数
- C语言qsort函数算法性能测试
- C语言函数调用性能测试
- Python性能测试函数
- Python函数性能测试
- linux C 高精度时间函数:gettimeofday()
- 【高精度】高精度分数[c++]
- VxWorks6.9 辅助时钟,高精度定时器精度测试函数!
- 性能测试-函数性能分析篇
- 性能测试-函数性能分析篇
- 性能测试-函数性能分析篇
- LoadRunner 性能测试脚本-函数
- pow函数的性能测试
- 简单性能测试函数模板
- linux c++性能测试函数
- C-NCAP和性能测试
- C 函数调用测试
- 高精度算法数据结构及常用函数实现(C++)
- jfinal框架中ajax提交返回类型datatype不确定时。。。
- 程序C++ to C#交互
- 织梦dedecms — 图片集内所有图片调用(原图)
- https server
- JVM监控工具介绍jstack, jconsole, jinfo, jmap, jdb, jstat
- C++高精度性能测试函数
- VS中CUDA与C++工程项目的配置
- 麻将补花出现卡住
- 静态变量static
- linux上安装配置vsftpd
- 1015. Reversible Primes (20)
- 自定义圆形进度条
- getchar()用法
- 软件开发过程学习笔记(三)之概要设计说明书模板