c++ 统计函数执行时间class

来源:互联网 发布:mac用什么看图软件好 编辑:程序博客网 时间:2024/05/03 16:04

class TimeCount
{
public:
TimeCount(void);
~TimeCount(void);


void StartCount();
void EndCount(OUT double * seconds = NULL, IN bool print=false);


private:
clock_t m_start;
clock_t m_end;

};


TimeCount::TimeCount(void)
{
}


TimeCount::~TimeCount(void)
{
}


void TimeCount::StartCount()
{
m_start = clock();
}


void TimeCount::EndCount( OUT double * seconds /*= NULL*/, IN bool print )
{
m_end = clock();


double z_seconds = ((double)(m_end-m_start))/CLOCKS_PER_SEC;


if (seconds!=NULL)
{
*seconds = z_seconds;
}


if (print)
{
printf("<>函数执行了%f秒<> \n", z_seconds );
}
}

0 0
原创粉丝点击