help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Precompiled headers do not speed compilation up?


From: Markus Dehmann
Subject: Re: Precompiled headers do not speed compilation up?
Date: Tue, 18 Nov 2008 15:15:04 -0800 (PST)
User-agent: G2/1.0

Thanks for your answer. See my comments below.

On Nov 18, 6:01 am, Bernd Strieder <strie...@informatik.uni-kl.de>
wrote:
>
> Markus Dehmann wrote:
>
> > // main2.cpp
> > #include "all.h"
> > int main(){
> >   std::cout << "hello";
> > }
> > // all.h
> > #include <iostream
> > #include "header1.h"
> > #include "header2.h"
> > #include "header3.h"
>
> > // On the command line:
> > $ g++ all.h
> > $ g++ -c -o main2.o main2.cpp
>
> I don't think this is the real example taking 40 sec, and therefore you
> cannot see the point here.

But it *is* the case that takes 40 seconds. The small file I gave
above (main.cpp) takes 40 seconds to compile because of all the
included code (of course, I didn't show you the header files; just
assume they contain lots of code.).

You might ask why include all the headers you don't call anything from
the headers. The answer is that I gave this as a minimal example. In
practice, I also have some code in main.cpp that actually calls the
function from the header files. But even without those function calls,
just including the headers, it takes that long to compile.

> Since precompiled headers have some overhead, you will never have an
> advantage from using precompiled headers with a single or only a
> few .cc files, or when using precompiled headers only a few times. With
> many .cc files the overhead is over-amortized to a net win. So let's
> assume you have many .cc files.

I'm not sure what you mean. It is standard to compile each .cc file
separately into an object file. So you'd usually not give more than
one .cc file as g++ argument. Are you saying that, in this standard
situation where there is only one .cc file on the command line, there
will never be an advantage from precompile headers? Then they really
seem useless to me. But maybe I misunderstood.

Markus


reply via email to

[Prev in Thread] Current Thread [Next in Thread]