本文共 989 字,大约阅读时间需要 3 分钟。
.h 文件
/* * commonfunction.h * * Created on: Sep 2, 2019 * Author: huanglei */#ifndef COMMONFUNCTION_H#define COMMONFUNCTION_Husing namespace std;extern maptimerMap;void start(const string& name);double stop(const string& name);
.cpp 文件
common#include "commonFunction.h"maptimerMap;void start(const string& name) { // timerMap.clear(); timespec ts1; clock_gettime(CLOCK_REALTIME, &ts1); timerMap[name] = ts1;}double stop(const string& name) { int isDebugAnalogOn=0; timespec ts1 = timerMap[name]; timespec ts2; clock_gettime(CLOCK_REALTIME, &ts2); double interval = (ts2.tv_sec - ts1.tv_sec)*1e3 + (ts2.tv_nsec - ts1.tv_nsec)/1e6;// GET_TESTFLOW_FLAG("debug_analog",&isDebugAnalogOn); if (isDebugAnalogOn) { cout << "DEBUG: timer " << name << " = " << interval << " ms " ; } return interval;}
用例:
#include "commonFunction.h"void codeTime(){ start("timer") double codeTime=stop("timer") cout<<
转载地址:http://asmzi.baihongyu.com/