C++ 与表达式或变量进行比较时的性能差异

C++ 与表达式或变量进行比较时的性能差异,c++,algorithm,C++,Algorithm,我想知道使用表达式处理控制流与将该表达式赋给变量并与之进行比较之间的性能差异(如果有的话)。 例如,以下各项之间的性能差异是什么: double testVal = pow((point.x-center.x), 2.0) + (pow((point.y-center.y), 2.0)); double radSqr = pow(radius, 2.0); if(testVal < radSqr) { .................... } else if(testVal == ra

我想知道使用表达式处理控制流与将该表达式赋给变量并与之进行比较之间的性能差异(如果有的话)。 例如,以下各项之间的性能差异是什么:

double testVal = pow((point.x-center.x), 2.0) + (pow((point.y-center.y), 2.0));
double radSqr = pow(radius, 2.0);
if(testVal < radSqr) {
....................
} else if(testVal == radSqr) { 
..................
}
double testVal=pow((point.x-center.x),2.0)+(pow((point.y-center.y),2.0));
双radSqr=功率(半径2.0);
if(testVal

if(功率((点x-center.x),2.0)+(功率((点y-center.y),2.0))
你问错了问题,下面是一篇有趣的文章,内容如下:


如果你真的想知道答案,那么如果做对了,你就是你的朋友:

任何优化编译器都会为你解决这个问题,不要为小事操心。区别在于,第一个代码编译时没有错误,而另一个代码编译时没有错误。
if(pow((point.x-center.x), 2.0) + (pow((point.y-center.y), 2.0)) < pow(radius, 2.0)) {
....................
} else if(testVal == radSqr) { 
..................
}