class RunTimeRecord
{
public:
RunTimeRecord(QString fu):fun(fu)
{
gettimeofday(&tpstart,NULL);
}
~RunTimeRecord()
{
gettimeofday(&tpend,NULL);
float time = (1000000*(tpend.tv_sec-tpstart.tv_sec) + tpend.tv_usec-tpstart.tv_usec)/1000000.0;
runTime += time;
qDebug()<<fun<<runTime<<" : "<<time<<endl;
}
static float runTime;
struct timeval tpstart;
struct timeval tpend;
QString fun;
};
float RunTimeRecord::runTime = 0;
#define RUNTIMER RunTimeRecord r(__FUNCTION__);
void test()
{
RUNTIMER
int i = 1000;
while(i--);
}
Linux测试函数运行时间
最新推荐文章于 2022-07-18 19:01:17 发布