21

I'm creating a fairly large library in C++0x using GCC 4.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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rcv
  • 6,078
  • 9
  • 43
  • 63

2 Answers2

28

g++ some_file.cc -ftime-report will give you a rough estimate of time spent in different compiler phases. The most important ones in your case are name lookup and parsing.

There isn’t any way to get a per class/function compile time alas.

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joel Falcou
  • 6,247
  • 1
  • 17
  • 34
  • 5
    said profiler link : https://svn.boost.org/svn/boost/sandbox/tools/profile_templates/ – Joel Falcou Jun 17 '11 at 19:58
  • 1
    This would be more useful if there were any semblance of docs on how to use it. – xaxxon Jul 11 '16 at 09:31
  • @xaxxon There's a 'doc' folder :) – Bulletmagnet Sep 11 '17 at 11:45
  • I'm having a hard time figuring out how to use it based on just the docs folder. Steven's original post has a little more context: http://boost.2283326.n4.nabble.com/Profiling-template-instantiations-td2657157.html – Fractaly Dec 05 '19 at 22:50
  • FTR: now that the original repo is gone, at least (a fork of) it can be seen at GitHub: https://github.com/psiha/profile_templates2 (which is itself abandonware for over a decade :) ). Any better pointer on this topic, BTW? E.g. has it perhaps been a compiler feature somewhere since then? – Sz. Aug 03 '23 at 19:23
1

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

Also if you have a multicore machine you may exploit make -jN to tell Make run N jobs at once.

Don't forget about precompiled headers too.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dimba
  • 26,717
  • 34
  • 141
  • 196
  • 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