[root@shanghai c++11]# cat test3.c
#include
int a(void) {
int i=0,g=0;
while(i++<200000)
{
g^=i;
}
return g;
}
int b(void) {
int i=0,g=0;
while(i++<800000)
{
g^=i;
}
return g;
}
int main(int argc, char** argv)
{
int iterations;
if(argc != 2)
{
printf("Usage %s \n", argv[0]);
return -1;
}
else
iterations = atoi(argv[1]);
printf("你键入的数是 = %d\n", iterations);
while(iterations--)
{
a();
b();
}
}
[root@shanghai c++11]#
[root@shanghai c++11]# gcc -g -pg test3.c && ./a.out 9999
你键入的数是 = 9999
[root@shanghai c++11]#
[root@shanghai c++11]# ll
total 64
-rwxr-xr-x 1 root root 10176 Mar 22 16:33 a.out
-rw-r--r-- 1 root root 471 Mar 22 16:34 gmon.out
-rw-r--r-- 1 root root 537 Mar 22 16:33 test3.c
[root@shanghai c++11]#
[root@shanghai c++11]# gprof a.out gmon.out > log
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
81.22 21.19 21.19 9999 2.12 2.12 b
19.88 26.38 5.19 9999 0.52 0.52 a
index % time self children called name
[1] 100.0 0.00 26.38 main [1]
21.19 0.00 9999/9999 b [2]
5.19 0.00 9999/9999 a [3]
-----------------------------------------------
21.19 0.00 9999/9999 main [1]
[2] 80.3 21.19 0.00 9999 b [2]
-----------------------------------------------
5.19 0.00 9999/9999 main [1]
[3] 19.7 5.19 0.00 9999 a [3]
-----------------------------------------------