Profiling with Valgrind
Investigate Program Cost
valgrind --tool=callgrind $PROGRAMNAME
This will create an output file which can be opened with
kcachegrind $CALLGRIND_OUT_FILE
Search for Memory Leaks
valgrind --tool=memcheck --leak-check=full $PROGRAMNAME