编译器优化问题 [英] Compiler optimization problem
本文介绍了编译器优化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< functional>
中的大多数函数使用函子。如果我写这样的结构:
Most of the functions in <functional>
use functors. If I write a struct like this:
struct Test
{
bool operator()
{
//Something
}
//No member variables
};
是否会创建 Test
的对象?还是可以编译器优化对象呢?
Is there a perf hit? Would an object of Test
be created? Or can the compiler optimize the object away?
推荐答案
GCC至少可以优化对象创建和内联函数,所以你可以期望性能像手工循环。您必须使用-O2编译cource。
GCC at least can optimize the object creation and inline your functor, so you can expect performance as with hand-crafted loop. Of cource you must compile with -O2.
这篇关于编译器优化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文