Recommendations for C Profilers?

Michael picture Michael · Nov 25, 2009 · Viewed 32.9k times · Source

Everyone always says to profile your program before performing optimizations but no-one ever describes how to do so.

What are your practices for profiling C code?

Answer

Alex Martelli picture Alex Martelli · Nov 25, 2009

Using gcc, I compile and link with -pg (as explained e.g. here), then continue by running the program (according to the principles also suggested at that URL) and using gprof. The tools will vary if you're using different compilers &c, but the URL is still recommended, even then, for the parts that are about general ideas on how and why to profile your code.