Profiling of Code Using gprof
Learn about another tool, gprof, available in C and how it helps us find out the program execution time.
We'll cover the following...
We'll cover the following...
Profiling refers to the process of collecting statistics about how a program executes in order to identify bottlenecks in performance and improve program efficiency.
How to use the GNU profiler
There is a UNIX utility program called gprof that can help us determine which parts of our program are taking most execution time.
The basic steps are:
- Compile the program with profiling enabled (using the
-pgcompiler flag). - Execute the program once to generate a profile data file.
- Run the
gprofcommand to analyze the profile data.
Here is an example program that does some number crunching and that we wish to profile: