假设我们想知道函数的运行多久,我们就可以这样写代码如何编写一个获取函数运行时的宏?
struct timeval tpstart,tpend;
gettimeofday(&tpstart,NULL);
A();
gettimeofday(&tpend,NULL);
float timeuse= tpend.tv_sec-tpstart.tv_sec + (tpend.tv_usec-tpstart.tv_usec)/1000000;
printf("Used Time:%f\n",timeuse);
但我怎么可以把它封装到一个宏这样的运行时(A),也许,运行(A,B,。 ..),有时几个功能一起运行。
'gettimeofday'是不是标准的C还宣布POSIX过时,可以考虑使用'从POSIX或'timespec_get clock_gettime' '从C11开始。 –
好的,这是我通过google获得的代码段,我从来没有在 – stonestrong