20

I'm creating a fairly large library in C++(0X) using gcc4.6 in linux. My library relies heavily on template classes, resulting in long compile times for applications which use the library. I would like to start speeding things up by providing explicit instantiations of the worst offending types/methods.

Is there a way to have gcc report the time spent compiling various types/methods so that I can apply my explicit instantiations in a principled way, rather than through intuition?

rcv
  • 5,712
  • 9
  • 40
  • 62

2 Answers2

27

g++ some_file.cc -ftime-report

will give you a rough estimate of time spent in different compiler phase. Most important ones in your case are name lookup and parsing.

No way to get a per class/function compile time alas.

STeven Watanabe has proposed a template profiler , available in boost sandbox that helps getting the number of potential instantiation of anything in a .cc

Joel Falcou
  • 6,057
  • 1
  • 16
  • 34
1

I know that it's not what you're looking for, but maybe ccache/distcc may help to speed up compilation.

Also if you have multi core machine you may exploit make -jN to tell make run N jobs at once.

Don't forget about precompiled headers too.

dimba
  • 25,491
  • 29
  • 135
  • 190
  • Fortunately, I have server farm on which I compile - However, I'm trying to make things faster for any poor user that wants to compile all of these crazy templates. – rcv Jun 17 '11 at 22:31