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

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 analyze 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.

Continue your learning journey with a 14-day free trial.

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