linux timing profile

时间:2023-03-09 15:11:24
linux timing  profile
double getUnixTime(void)
{
struct timespec tv; if(clock_gettime(CLOCK_REALTIME, &tv) != ) return ; return (((double) tv.tv_sec) + (double) (tv.tv_nsec / 1000000000.0));
} double start_time = getUnixTime();
double stop_time, difference; algorithm(); stop_time = getUnixTime();
difference = stop_time - start_time;
printf("elipsed time :%lf\ns",difference);

g++ t.c++ -lrt

gprof

gprof -b -p astart gmon.out >&tmp.txt

@ gprof hello gmon.out -p 得到每个函数占用的执行时间
       @ gprof hello gmon.out -q 得到call graph,包含了每个函数的调用关系,调用次数,执行时间等信息。
       @ gprof hello gmon.out -A 得到一个带注释的“源代码清单”,它会注释源码,指出每个函数的执行次数。这需要在编译的时候增加 -g选项。

http://www.thegeekstuff.com/2012/08/gprof-tutorial/