Profiling of Code Using gprof

Learn about another tool gprof that's available in C and how it helps us find out the program execution time.

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:

  1. compile the program with profiling enabled (using the -pg compiler flag)
  2. execute the program once to generate a profile data file
  3. run the gprof command to analyse the profile data

Here is an example program that does some number crunching and that we wish to profile:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy