Bud*_*ika 3 c++ optimization assembly compiler-optimization c++17
假设我们多次定义const或constexpr做简单的算术运算符,变量和函数调用也不会表示或返回常量。
#define NU = 3; //Macro or
const int NU = 3 // general declaration or constexpr
auto NU = []()constexpr -> int { return 3;}
int result = 0;
#Approach one -> const NU on left side of the operator right side could be function call or a function parameter
for(int i = 0; i< SOME_MAX; ++i) result = NU * foo(); // function call or
for(int i = 0; i< SOME_MAX; ++i) result = NU * var; // variable
#Approach two -> const NU on Right side of the operator Left side could be function call or a function parameter
for(int i = 0; i< SOME_MAX; ++i) result = foo() * NU ;// function call or
for(int i = 0; i< SOME_MAX; ++i) result = var * NU; // variable
Run Code Online (Sandbox Code Playgroud)
哪种方法将生成优化的汇编->机器代码?
相对于算术运算符,在LHS或RHS上的常量操作数是否会影响优化或性能?
注意-在这里我用它来描述我的想法,性能下降或效率低下可以忽略不计,但是,假设使用一组常数进行一组复杂的数学运算。
谢谢。
| 归档时间: |
|
| 查看次数: |
98 次 |
| 最近记录: |