This is a slower approach to return to a faster runtime, but if you want to better understand what causes big changes, you can do a few “experiments”
One experiment would be to find which function may be responsible for large changes. To do this, you can "profile" the execution time of each function.
For example, use GNU gprof, part of GNU binutils: http://www.gnu.org/software/binutils/
Docs: http://sourceware.org/binutils/docs-2.22/gprof/index.html
This will measure the time spent by each function in your program and where it was called from. Performing these measurements is likely to have the “Heisenberg effect”; measurements will affect program performance. So you can try an experiment to determine which class has the biggest difference.
Try to get an idea of how the runtime differs between the source code of a class in the main source and the same program, but with the class compiled and linked separately.
To get the implementation of the class in the final program, you can either compile it, or link it, or simply include it in the "main" program, and then compile the main one.
To make it easier to swap, you can enable or disable #include with #if:
#if defined(CLASSA) // same as #ifdef CLASSA #include "classa.cpp" #endif #if defined(CLASSB) #include "classb.cpp" #endif
Then you can control which files: #include using command line flags for the compiler, for example
g++ -DCLASSA -DCLASSB ... main.c classc.cpp classd.cpp classf.cpp
It may take just a few minutes to generate permutations of -Dflags and command references. Then you will have the opportunity to generate all the compilation permutations "in one unit" individually, and then run (and time) each.
I assume your header files are wrapped in plain
#ifndef _CLASSA_H_ #define _CLASSA_H_
Then you will have some information about the important class.
These experiments may provide some insight into the behavior of the program and the compiler, which may stimulate some other ideas for improvement.