在实际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 500
inline 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);
Outp