I need to profile my C++ code, and valgrind --tool=callgrind
is a phenomenal tool for that. I was wondering, however, if I should be profiling my code with -g -pg -O1
or -g -pg -O3
(GCC 4.4.7)? The latter gives a more accurate depiction of my program's performance, but I worry that -O3
will confuse the profiler and obfuscate what source functions are the actual bottlenecks. Perhaps I am just scared of old wive's tales, but I figured I should ask to be sure before running a potentially several hour test.
This thread in another stackoverflow may clear your mind: optimization flags when profiling
The problem is not profiling with optimization, but debugging with optimization (-g -pg).
As quantdev said, you should "always use the same options as the one used to create production binaries", and you are ont going to create a production binary with debug information.
If the thread is not enough, let us know.