Profiling your code using `gprof`

Another tool available in C is 'gprof'. We'll see its functionality and how it helps us understand the program runtime.

We'll cover the following

There is a unix utility program called gprof (GNU profiler) that can help you determine which parts of your program are taking most execution time.

The basic steps are:

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

Here is an example program 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