I was using g++ 4.7 because it's one of the latest release of g++ and it's the first one that adds a real support for c++11
.
For testing purpose I'm considering code taken from here.
You can find the complete source code here.
I name this source lambda.cpp and i compile it with:
g++-4.6 -std=c++0x lambda.cpp -o lambda46
g++-4.7 -std=c++11 lambda.cpp -o lambda47
the lambda47 executable is about an half second slower than lambda46 when it comes to lambda performances, the surprise it's that the iterator part is usually faster than lambda46.
I have also tried to use
g++-4.7 -std=c++0x lambda.cpp -o lambda47-0x
but basically g++-4.6 always generates faster code than g++-4.7.
This is a common behaviour or it's a bug ?
There is a compiler that will perform better with C++11 ?
g++-4.7 it has been compiled with
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-4precise1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
g++-4.6 with
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
In my case, the lambda version is faster with both g++ 4.6 and 4.7 (and g++ 4.7 produce faster code than 4.6). The only difference with you is that I am using 32bit version of the compilers.
But if I compile your code with -O3, iterator are faster by about 2 seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With