Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: (OT) Profiling under gcc

Author: Robert Hyatt

Date: 13:40:53 05/23/02

Go up one level in this thread


On May 23, 2002 at 13:52:28, Sven Reichard wrote:

>Thanks for your input. Cf. answer to Dr. Hyatt.
>
>To give you a better idea, here is a short transcript. You see that gprof
>doesn't notice that the program takes any time at all.
>
>Cheers,
>Sven.
>
>
>[sven@localhost TestProfile]$ more main.cpp
>void f(int depth)
>{
>  if (! depth){
>    for (int i = 0; i < 10000; i++);
>    return;
>  }


Note that if you optimize, the compiler might take that for loop and throw
it totally away.  If I is global, it could replace the for loop with a simple
i=10000; and then return.

If you don't do any optimizing, then that loop will still probably execute
inside the resolution of the cpu clock (18ms roughly) which will screw up the
timing.  You need to profile something that runs for a long time...  say a
minute.  When I do profile-based optimizing, I run the profile test for at
least 10 minutes over a set of positions, then use the profiling result to
re-compile...




>  f(depth-1);
>  f(depth-1);
>};
>
>int main()
>{
>  f(15);
>  return 0;
>};
>[sven@localhost TestProfile]$ make
>g++ -g  -pg   -c -o main.o main.cpp
>g++ -g  -pg -o main main.o
>[sven@localhost TestProfile]$ time ./main
>
>real    0m3.239s
>user    0m1.670s
>sys     0m0.000s
>[sven@localhost TestProfile]$ gprof -b ./main
>Flat profile:
>
>Each sample counts as 0.01 seconds.
>  %   cumulative   self              self     total
> time   seconds   seconds    calls  us/call  us/call  name
>100.00      0.01     0.01        1 10000.00 10000.00  f(int)
>
>
>                        Call graph
>
>
>granularity: each sample hit covers 4 byte(s) for 100.00% of 0.01 seconds
>
>index % time    self  children    called     name
>                               65534             f(int) [1]
>                0.01    0.00       1/1           main [2]
>[1]    100.0    0.01    0.00       1+65534   f(int) [1]
>                               65534             f(int) [1]
>-----------------------------------------------
>                                                 <spontaneous>
>[2]    100.0    0.00    0.01                 main [2]
>                0.01    0.00       1/1           f(int) [1]
>-----------------------------------------------
>
>
>Index by function name
>
>   [1] f(int)



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.