Re: Seeing a lot of time to compile with g++ 3.3.6
On Nov 2, 9:46 pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
I have been seeing a consistent slowness in g++ compilation
for a small file like the following , The uptime is near (
load Is near to 0 ) . I have put the time output for the same,
The file looks like the following
#include<iostream>
#include<vector>
#include<deque>
using namespace std;
int main()
{
int data[5] = {6,7,8,6,5};
vector<int> v(5,6);
deque<int> d(data, data+5);
deque<int>::iterator p;
cout << "\n Deque values" <<endl;
for (p= d.begin(); p!= d.end(); ++p)
cout <<*p<<'\t';
cout <<endl;
d.insert(d.begin(), v.begin(), v.end());
for (p= d.begin() ; p != d.end(); ++p)
cout<<*p <<'\t';
cout <<endl;
}
First, of course, what the compiler "compiles" is the output of
the preprocessor, with all of the includes. Try doing a line
count of that. Option /E for VC++, -E almost universally for
Unix based compilers---if you're on Unix, the output of "g++ -E
source.cc | wc -l" might surprise you.
Secondly, compiling templates *is* hard work, and you've got a
lot of templates there. (Don't forget that all of iostream is
also templated.) With Sun CC, I can request compatibility with a
very old, pre-standard version of the compiler, where
<iostream.h> is not templated---hello, world compiles ten times
faster if I do. The difference for most real programs isn't
that significant, of course, because in most of my real
programs, most lines of code don't involve templates. But the
fact that iostream is a template does mean that most of the
implementation is physically in the headers, and must be read by
the compiler; when the network is slow, I still notice.
a.outvgamd261> /usr/bin/time g++ p237.cc
0.84user 0.17system 0:05.14elapsed 19%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (1968major+20640minor)pagefaults 0swaps
Off hand, it looks like the problem is reading the sources
(including the headers). Unless you've got something else going
on which uses a lot of C++, the only thing which could explain
the different between less that a second user time and over 5
seconds elapsed time is IO wait.
You might look at where the g++ headers are installed. If
they're on a slow disk, or remote mounted over a slow network,
copying them to a fast disk or locally might spead things up.
Also, if you have enough main memory, you'll probably notice
that when you compile a lot of sources one after the other, only
the first one is particularly slow; for the others, the header
data is still cached in the system, and doesn't have to be read
again from disk.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34