Take a look at your compiler's options for precompiled headers. In GCC, for example, passing a header as if it is a source causes it to be precompiled.
It reduced time significantly for my little test, but only if you don't count the time spent precompiling:
Shadow:code dkrauss$ ls maps*
maps.cpp maps.h maps2.cpp
Shadow:code dkrauss$ cat maps*
#include "maps.h"
using namespace std;
map<int,int> ints;
map<string, string> strings;
map<int, string> is;
map<string, int> si;
int main() {
bang(ints);
bang(strings);
bang(is);
bang(si);
extern void more();
more();
}
#include <string>
#include <map>
template< class K, class V >
void bang( std::map<K,V> &v ) {
v[ K() ] = V();
v.erase( v.begin() );
}
#include "maps.h"
using namespace std;
map<int,int> ints2;
map<string, string> strings2;
map<int, string> is2;
map<string, int> si2;
void more() {
bang(ints2);
bang(strings2);
bang(is2);
bang(si2);
}
Shadow:code dkrauss$ time g++ maps*.cpp -o maps
real 0m1.091s
user 0m0.857s
sys 0m0.132s
Shadow:code dkrauss$ time g++ maps.h
real 0m0.952s
user 0m0.406s
sys 0m0.110s
Shadow:code dkrauss$ ls maps*
maps maps.cpp maps.h maps.h.gch maps2.cpp
Shadow:code dkrauss$ time g++ maps*.cpp -o maps
real 0m0.718s
user 0m0.552s
sys 0m0.095s
Shadow:code dkrauss$