g++ compilation is slow with Boost's constructs
Hello, I've been using several Boost libraries since 1.33 and now I have a situation that it takes over 4 seconds to compile for some files <= 40Kb (not so big!), with gcc. I've upgraded my machine recently (AMD X3 425, 2700MHz, 2GB memory) and hoped that things would change but it is still somewhat a blocker to developing. So I began to investigate and found out each invocation of known Boost constructs has its non-zero cost. I chose a source file(*), commented out all and then incrementally uncommented functions from beginning, compiled and measured times. Here is my results (compile time, not run time!): - BOOST_FOREACH costs 0.1 sec - boost::function<> invocation costs 0.05 sec - boost::lambda::bind() with placeholders costs 0.1 sec - Boost.Range adaptor transformed() costs ~0.1 too As you can see, 10 boost::lambda::bind() slow down your compilation for whole 1 second! All that is measured against gcc 4.4, Ubuntu 9.10, with the most light options I picked up: "g++ -g -O0 -pipe" (I need -g for debugging anyway). Also I found out that gcc 4.2 is the quickest from 4.1, 4.2, 4.3, 4.4 version of gcc, and gcc 4.4 is the most slow one of them (~28% slower than gcc 4.2). :( Therefore, I have a few questions. 1) Are there more means/tricks for faster compilation with g++ I miss? (what a quickest gcc version?) 2) What compiler is known to be much more speedy for now, if any (icc, clang, msvc)? 3) Did someone try to investigate (and maybe fix) that gcc bottleneck(s)? Regards, Ilya Murav'jov (*) I did measures on a source file select.cpp from my project, Bombono DVD (http://gitorious.org/bombono-dvd/bombono-dvd/blobs/master/src/mgui/editor/se...)
Hi,
I'm not a specialist but I know that :
2) What compiler is known to be much more speedy for now, if any (icc,
clang, msvc)?
MSVC is globally faster than GCC with the same code (I don't know if things
changed in GCC 4.5 and if invoking several jobs works better than with
msvc), and CLang is also meant to be radically faster than GCC. See
http://clang.llvm.org/performance.html
On Tue, Sep 7, 2010 at 00:23, Ilya Murav'jov
2) What compiler is known to be much more speedy for now, if any (icc, clang, msvc)? 3) Did someone try to investigate (and maybe fix) that gcc bottleneck(s)?
Klaim пишет:
msvc), and CLang is also meant to be radically faster than GCC. See http://clang.llvm.org/performance.html
There is nothing about C++, only about C and Objective-C. Anything more about Clang? Regards, Ilya
On Tue, Sep 7, 2010 at 9:46 AM, Ilya Murav'jov
Klaim пишет:
msvc), and CLang is also meant to be radically faster than GCC. See http://clang.llvm.org/performance.html
There is nothing about C++, only about C and Objective-C. Anything more about Clang?
In my own personal experience, clang is about 500% faster then GCC on my Ubuntu system with identical highly templated Boost code, but then I have GCC 4.4 installed as well, GCC 4.5 is a *lot* faster in many cases then 4.4. GCC in general does still produce faster code then clang though, so it is a trade-off.
On 09/07/2010 09:08 PM, OvermindDL1 wrote:
On Tue, Sep 7, 2010 at 9:46 AM, Ilya Murav'jov
wrote: Klaim пишет:
msvc), and CLang is also meant to be radically faster than GCC. See http://clang.llvm.org/performance.html
There is nothing about C++, only about C and Objective-C. Anything more about Clang?
In my own personal experience, clang is about 500% faster then GCC on my Ubuntu system with identical highly templated Boost code, but then I have GCC 4.4 installed as well, GCC 4.5 is a *lot* faster in many cases then 4.4. GCC in general does still produce faster code then clang though, so it is a trade-off.
ccache might help, if you recompile things often. It is a wrapper for gcc which caches compilation results. Very nice :-)
Roland Bock пишет:
ccache might help, if you recompile things often. It is a wrapper for gcc which caches compilation results. Very nice :-)
The main use case is 1) edit one file 2) compile (3) maybe link&test). In such situations ccache, distcc and even multi-core CPU are useless. I want to remark that PCH is another facility I use to reduce compile time. It speeds up the compilation at 50% with gcc. Regards, Ilya
On Mon, Sep 6, 2010 at 6:23 PM, Ilya Murav'jov
So I began to investigate and found out each invocation of known Boost constructs has its non-zero cost. I chose a source file(*), commented out all and then incrementally uncommented functions from beginning, compiled and measured times. Here is my results (compile time, not run time!): - BOOST_FOREACH costs 0.1 sec - boost::function<> invocation costs 0.05 sec - boost::lambda::bind() with placeholders costs 0.1 sec - Boost.Range adaptor transformed() costs ~0.1 too As you can see, 10 boost::lambda::bind() slow down your compilation for whole 1 second!
All that is measured against gcc 4.4, Ubuntu 9.10, with the most light options I picked up: "g++ -g -O0 -pipe" (I need -g for debugging anyway). Also I found out that gcc 4.2 is the quickest from 4.1, 4.2, 4.3, 4.4 version of gcc, and gcc 4.4 is the most slow one of them (~28% slower than gcc 4.2). :(
G++4.5 implements O(1) template lookup, which could have a significant effect for Boost users. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
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. To be sure that I make gcc builds as quick as distro ones, I've built gcc-4.2 too and the results are the same (the quickest). Regards, Ilya
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
On Thu, Sep 9, 2010 at 10:17 AM, Ilya Murav'jov
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 #include // boost::function typedef boost::function
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.
On Fri, Sep 10, 2010 at 7:37 PM, OvermindDL1
On Thu, Sep 9, 2010 at 10:17 AM, Ilya Murav'jov
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 #include // boost::function typedef boost::function
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
On Fri, Sep 10, 2010 at 7:38 PM, OvermindDL1
On Fri, Sep 10, 2010 at 7:37 PM, OvermindDL1
wrote: On Thu, Sep 9, 2010 at 10:17 AM, Ilya Murav'jov
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 #include // boost::function typedef boost::function
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
And compiling it in MSVC2k5 I got: Release: Build Time 1:28 Debug: Build Time 1:00 In MSVC2k5 I was using WinXP 32-bit, for clang++/g++ I was using Ubuntu 10.04 in a virtual machine with hardware virtualization enabled on top of this WinXP 32-bit machine.
OvermindDL1 пишет:
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
Yes, -g making things slower.
And compiling it in MSVC2k5 I got: Release: Build Time 1:28 Debug: Build Time 1:00
In MSVC2k5 I was using WinXP 32-bit, for clang++/g++ I was using Ubuntu 10.04 in a virtual machine with hardware virtualization enabled on top of this WinXP 32-bit machine.
I assume 1:00 means 1 second, not 1 minute. :) Then it is quite fast.
On Sat, Sep 11, 2010 at 4:10 PM, Ilya Murav'jov
OvermindDL1 пишет:
And compiling it in MSVC2k5 I got: Release: Build Time 1:28 Debug: Build Time 1:00
In MSVC2k5 I was using WinXP 32-bit, for clang++/g++ I was using Ubuntu 10.04 in a virtual machine with hardware virtualization enabled on top of this WinXP 32-bit machine.
I assume 1:00 means 1 second, not 1 minute. :) Then it is quite fast.
Nope, 1 minute and one minute and 28 seconds, MSVC was very slow on that, but it is usually slow anyway, does make faster executing code though to be honest...
OvermindDL1 пишет:
On Sat, Sep 11, 2010 at 4:10 PM, Ilya Murav'jov
wrote: OvermindDL1 пишет:
And compiling it in MSVC2k5 I got: Release: Build Time 1:28 Debug: Build Time 1:00
In MSVC2k5 I was using WinXP 32-bit, for clang++/g++ I was using Ubuntu 10.04 in a virtual machine with hardware virtualization enabled on top of this WinXP 32-bit machine. I assume 1:00 means 1 second, not 1 minute. :) Then it is quite fast.
Nope, 1 minute and one minute and 28 seconds, MSVC was very slow on that, but it is usually slow anyway, does make faster executing code though to be honest...
Hmm, it's interesting. Then MSVC is very slow with that. Regards, Ilya
Dave Abrahams пишет:
On Mon, Sep 6, 2010 at 6:23 PM, Ilya Murav'jov
wrote: So I began to investigate and found out each invocation of known Boost constructs has its non-zero cost. I chose a source file(*), commented out all and then incrementally uncommented functions from beginning, compiled and measured times. Here is my results (compile time, not run time!): - BOOST_FOREACH costs 0.1 sec - boost::function<> invocation costs 0.05 sec - boost::lambda::bind() with placeholders costs 0.1 sec - Boost.Range adaptor transformed() costs ~0.1 too As you can see, 10 boost::lambda::bind() slow down your compilation for whole 1 second!
All that is measured against gcc 4.4, Ubuntu 9.10, with the most light options I picked up: "g++ -g -O0 -pipe" (I need -g for debugging anyway). Also I found out that gcc 4.2 is the quickest from 4.1, 4.2, 4.3, 4.4 version of gcc, and gcc 4.4 is the most slow one of them (~28% slower than gcc 4.2). :(
G++4.5 implements O(1) template lookup, which could have a significant effect for Boost users.
Ok, I've done some benchmarking with g++ 4.5, g++ 4.2 and clang 1.1/llvm 2.7. Compilation time is measured with "-c -g -O0 -pipe", with Boost 1.44 . 1) 100 invocations of boost::lambda::bind(), http://gitorious.org/bombono-dvd/bombono-dvd/blobs/master/src/mlib/tests/pro... : g++ 4.5: 9.57 sec g++ 4.2: 14.75 sec clang++ 1.1/llvm 2.7: 6.00 sec MSVC2k5(OvermindDL1): 1.00 sec 2) 100 invocations of BOOST_FOREACH, http://gitorious.org/bombono-dvd/bombono-dvd/blobs/master/src/mlib/tests/pro... : g++ 4.5: 3.15 sec g++ 4.2: 3.95 sec clang++ 1.1/llvm 2.7: 3.07 sec 3) 100 invocations/instantiations of boost::function, http://gitorious.org/bombono-dvd/bombono-dvd/blobs/master/src/mlib/tests/pro... : g++ 4.5: 3.20 sec g++ 4.2: 3.30 sec clang++ 1.1/llvm 2.7: 2.74 sec 4) 100 invocations/instantiations boost::adaptors::filtered (Boost.Range' filter on top of Boost.Iterator), http://gitorious.org/bombono-dvd/bombono-dvd/blobs/master/src/mlib/tests/pro... : g++ 4.5: 4.27 sec g++ 4.2: 6.60 sec clang++ 1.1/llvm 2.7: 3.48 sec Regards, Ilya P.S. I must admit that tests are rather synthetic but they do show the degrees of compilers speeds.
On 06/09/2010 23:23, Ilya Murav'jov wrote:
- BOOST_FOREACH costs 0.1 sec - boost::function<> invocation costs 0.05 sec - boost::lambda::bind() with placeholders costs 0.1 sec - Boost.Range adaptor transformed() costs ~0.1 too As you can see, 10 boost::lambda::bind() slow down your compilation for whole 1 second!
Templates are memoized, so the cost of n instantiations is typically quite less than n times the cost of one instantiation.
Mathias Gaunard пишет:
On 06/09/2010 23:23, Ilya Murav'jov wrote:
- BOOST_FOREACH costs 0.1 sec - boost::function<> invocation costs 0.05 sec - boost::lambda::bind() with placeholders costs 0.1 sec - Boost.Range adaptor transformed() costs ~0.1 too As you can see, 10 boost::lambda::bind() slow down your compilation for whole 1 second!
Templates are memoized, so the cost of n instantiations is typically quite less than n times the cost of one instantiation.
Yes, you're right (maybe I misused the terms a little). But in a typical source file most applications of templates lead to "different" instantiations (so memoization can't help), especially with boost::lambda::bind() . Regards, Ilya
participants (6)
-
Dave Abrahams
-
Ilya Murav'jov
-
Klaim
-
Mathias Gaunard
-
OvermindDL1
-
Roland Bock