help-gplusplus
[Top][All Lists]
Advanced

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

Inheritance - why so slow?


From: Krzysztof Duleba
Subject: Inheritance - why so slow?
Date: Mon, 4 Oct 2004 18:50:34 +0200

Try this perl code that generates C++ source files.

perl -e 'print "class A0{};\n";print "class A$_:public A",$_-1,"{};\n"
for(1..$ARGV[0]);print "int main(){}\n"'   _number_

When _number_ is even quite small, my g++ compiles the code very, very
slow. For instance:

_number_    time
100       0,687s
200       4,080s
300      13,855s
400      35,328s


This is even better:

perl -e 'print "class A0{};\n";for(1..$ARGV[0]){print "class A$_:public ";
for($i=$_-1;$i>=1;--$i){print "A$i,"}print "A0{};\n";}
print "int main(){}\n"'    _number_

This code generates some compilation warnings, so it's better to disable
them first.

_number_    time
10        0,620s
11        1,670s
12        9,127s
13        -

In the last case, when _number_ == 13, g++ failed to compile the code and
bailed out. Before that, it was running for about 40s and used as much as
640 MB of memory.

Tested with 2.95 (Cygwin, Debian), 3.31 (Cygwin), 3.33 (Cygwin), 3.34
(Debian, PLD) and 3.4 (Debian).

Visual C++ .NET handles it in no time. Is g++ using some exponential algo?

Regards
Krzysztof Duleba






reply via email to

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