Boost logo

Boost Users :

Subject: Re: [Boost-users] g++ compilation is slow with Boost's constructs
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-09-10 21:38:58


On Fri, Sep 10, 2010 at 7:37 PM, OvermindDL1 <overminddl1_at_[hidden]> wrote:
> On Thu, Sep 9, 2010 at 10:17 AM, Ilya Murav'jov <muravev_at_[hidden]> wrote:
>> Jason Merrill пишет:
>>> > On 09/08/2010 07:40 AM, Ilya Murav'jov wrote:
>>>> >> Dave Abrahams пишет:
>>>>> >>> G++4.5 implements O(1) template lookup, which could have a
>> significant
>>>>> >>> effect for Boost users.
>>>> >>
>>>> >> Thanks for the info. I've built gcc-4.5.1 myself and got not very
>>>> >> comforting results: g++4.2 is still 'unbeaten', g++4.5 is 15% slower.
>>> >
>>> > Hmm, that's disappointing.  I grabbed the source file you mentioned, but
>>> > it seems to depend on other headers from your project; if you send me a
>>> > preprocessed file I'll try to take a look at what's slowing it down
>>> > sometime soon.
>>> >
>>> > Jason
>>> >
>>
>> After some experiments I've done a clear example. It shows that
>> boost::lambda::bind() invocation cost 0.1 sec. Here is the code:
>>
>> //////////////////// begin ////////////////////////
>>
>> #include <boost/lambda/bind.hpp>   // boost::lambda::bind
>> #include <boost/function.hpp>      // boost::function
>>
>> typedef boost::function<void()> TestFunctor;
>>
>> template<int value>
>> struct TestStruct
>> {
>> };
>>
>> #define IMPL_DEF_(Idx, Type) void Impl ## Idx(Type) {} \
>> void TestImpl ## Idx()                           \
>> {                                                \
>>    TestFunctor fnr;                           \
>>    fnr = boost::lambda::bind(&Impl ## Idx, Type());  \
>> } \
>> /**/
>>
>> #define IMPL_DEF(Idx) IMPL_DEF_(Idx, TestStruct<Idx>)
>>
>> #define IMPL_DEF_10_(Idx) \
>> IMPL_DEF(Idx ## 0) \
>> IMPL_DEF(Idx ## 1) \
>> IMPL_DEF(Idx ## 2) \
>> IMPL_DEF(Idx ## 3) \
>> IMPL_DEF(Idx ## 4) \
>> IMPL_DEF(Idx ## 5) \
>> IMPL_DEF(Idx ## 6) \
>> IMPL_DEF(Idx ## 7) \
>> IMPL_DEF(Idx ## 8) \
>> IMPL_DEF(Idx ## 9) \
>> /**/
>>
>> #define IMPL_DEF_10(Idx) IMPL_DEF_10_(Idx)
>>
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>> IMPL_DEF_10(__LINE__)
>>
>> //////////////////// end ////////////////////////
>>
>> It does 100 invocations of boost::lambda::bind() with various types.
>> Benchmarks with "-c -g -O0 -pipe", Boost 1.44:
>>
>> G++ 4.2.4: 14.75 sec
>> G++ 4.5.1: 09.57 sec
>>
>> P.S. It shows that  g++4.5 is quicker, though.  :)  Later I try to do
>> examples with other constructs (BOOST_FOREACH, Boost.Range, B.Function)
>> to find out where g++4.2 is better.
>>
>> P.S.S. I suggest to make comparison among varios compilers (i.e., clang,
>> msvc, icc) with this test. It is interesting to see the quickest (don't
>> forget to include your CPU).
>
> I have an AMD Phenom II CPU, 3.2ghz, my times:
>
> home:/home/overminddl1/projects/testingrandom# g++ -v
> Using built-in specs.
> Target: i486-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Ubuntu
> 4.4.3-4ubuntu5'
> --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
> --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
> --enable-shared --enable-multiarch --enable-linker-build-id
> --with-system-zlib --libexecdir=/usr/lib --without-included-gettext
> --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4
> --program-suffix=-4.4 --enable-nls --enable-clocale=gnu
> --enable-libstdcxx-debug --enable-plugin --enable-objc-gc
> --enable-targets=all --disable-werror --with-arch-32=i486
> --with-tune=generic --enable-checking=release --build=i486-linux-gnu
> --host=i486-linux-gnu --target=i486-linux-gnu
> Thread model: posix
> gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
> home:/home/overminddl1/projects/testingrandom# ~/llvm/Release/bin/clang++ -v
> clang version 2.8 (trunk 113038)
> Target: i386-pc-linux-gnu
> Thread model: posix
> home:/home/overminddl1/projects/testingrandom# time g++ test.cpp
> /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
> (.text+0x18): undefined reference to `main'
> collect2: ld returned 1 exit status
>
> real    0m8.504s
> user    0m5.336s
> sys     0m0.184s
> home:/home/overminddl1/projects/testingrandom# time
> ~/llvm/Release/bin/clang++ test.cpp
> /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
> (.text+0x18): undefined reference to `main'
> collect2: ld returned 1 exit status
> clang: error: linker (via gcc) command failed with exit code 1 (use -v
> to see invocation)
>
> real    0m3.443s
> user    0m2.524s
> sys     0m0.188s
>
>
> However, clang++ usually does not compile code that runs quite as fast
> as g++ as of yet, but they are getting close, and yes, I know my g++
> is old, it is the stock install.

Guess I should use the same parameters you did, here it is:
home:/home/overminddl1/projects/testingrandom# time g++ test.cpp -c -g -O0 -pipe

real 0m9.404s
user 0m5.500s
sys 0m1.608s
home:/home/overminddl1/projects/testingrandom# time
~/llvm/Release/bin/clang++ test.cpp -c -g -O0 -pipe

real 0m4.644s
user 0m2.948s
sys 0m0.240s


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net