gprof sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
double func(double a){ | |
for (int i=0;i<100000000;i++){ | |
a = a * 3.0; | |
if (a > 1.0) a -= 1.0; | |
if (a > 1.0) a -= 1.0; | |
} | |
return a; | |
} | |
double func2(double a){ | |
for (int i=0;i<100000000;i++){ | |
a = a * 2.5; | |
if (a > 1.0) a -= 1.0; | |
if (a > 1.0) a -= 1.0; | |
} | |
return a; | |
} | |
int main(){ | |
double a = func(0.1); | |
double b = func2(0.1); | |
printf("%f %f\n",a,b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-pg
オプションをつけてコンパイルする。実行する。
gmon.outというファイルができている。
$ ls a.out* gmon.out test.cpp
この状態で
gprof
を実行する。$ gprof Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 56.33 1.15 1.15 1 1.15 1.15 func(double) 44.96 2.08 0.92 1 0.92 0.92 func2(double) (snip)
どの関数が何回呼ばれ、一度あたり何秒かかり、全体でどのくらいの割合を占めているかが表示される。