Seeing a lot of time to compile with g++ 3.3.6

P

parag_paul

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;
}



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
 
V

Victor Bazarov

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;
}



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

Uh... Yes. So? First off, the time it takes the compiler to compile
some code is non-normative. Some compilers are fast, some are slow.
Second, one man's trash is another man's treasure (meaning all things
are relative). Third, GCC is already past version 4, perhaps you need
to upgrade. Fourth, compilers are off-topic here, post the newsgroup
dedicated to it (gnu.g++.help) or use their web discussion forums.

V
 
J

James Kanze

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
BrentonMcc
Top