十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
double getUnixTime(void)
{
struct timespec tv;
if(clock_gettime(CLOCK_REALTIME, &tv) != 0) return 0;
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
s",difference);
g++ t.c++ -lrtgprof
gprof -b -p astart gmon.out >&tmp.txt
@ gprof hello gmon.out -p 得到每個(gè)函數(shù)占用的執(zhí)行時(shí)間
@ gprof hello gmon.out -q 得到call graph,包含了每個(gè)函數(shù)的調(diào)用關(guān)系,調(diào)用次數(shù),執(zhí)行時(shí)間等信息。
@ gprof hello gmon.out -A 得到一個(gè)帶注釋的“源代碼清單”,它會(huì)注釋源碼,指出每個(gè)函數(shù)的執(zhí)行次數(shù)。這需要在編譯的時(shí)候增加 -g選項(xiàng)。
http://www.thegeekstuff.com/2012/08/gprof-tutorial/