【发布时间】:2012-10-15 15:22:44
【问题描述】:
我使用的是 g++ 4.7,因为它是 g++ 的最新版本之一,也是第一个真正支持 c++11 的版本。
出于测试目的,我正在考虑采用from here 的代码。
You can find the complete source code here.
我将此源命名为 lambda.cpp 并编译它:
g++-4.6 -std=c++0x lambda.cpp -o lambda46
g++-4.7 -std=c++11 lambda.cpp -o lambda47
在 lambda 性能方面,lambda47 可执行文件比 lambda46 慢大约半秒,令人惊讶的是迭代器部分通常比 lambda46 快。
我也试过用
g++-4.7 -std=c++0x lambda.cpp -o lambda47-0x
但基本上 g++-4.6 生成的代码总是比 g++-4.7 更快。
这是一种常见的行为还是一个错误?
有一个编译器可以用 C++11 表现更好吗?
g++-4.7 已经编译过
配置为:../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 与
配置为:../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
【问题讨论】:
标签: lambda g++ performance-testing