performance - 表达式是否分配内存?
问题描述
考虑两个代码片段:
if (1 + 2 == 3) {
}
和
int a = 1;
int b = 2;
int result = 3;
int addition_result = a + b;
bool comparison = addition_result == result;
if (comparison) {
}
这些片段本质上是一样的吗?在第一种情况下,编译器是否在执行时为所有操作数分配内存:
1
2
3
1 + 2
1 + 2 == 3
(比较它true
)
还是第一个片段更有效,因为编译器不必为该表达式分配任何内存?
编译语言和解释语言有什么不同吗?
解决方案
推荐阅读
- javascript - Ajax 在确认弹出窗口上执行了两次。怎么修?
- javascript - 在预加载器页面渲染之前立即显示网站主页
- c++ - C++ - 指定模板值类型
- python - 如何防止拆分字符串中的转义换行符(python)
- visual-studio-code - Windows 10 上的 Vscode - 无法为 Julia 1.5.3 启动可执行 shell 的路径
- firebase - Firebase Functions 部署需要在 GCP 中进行键盘输入
- autodesk-forge - 发送较大文件时出现重叠范围错误
- php - 在 magento 2.4.1 中应用更新命令后,前端缺少图标、图像和 javascript 文件?
- asp.net-core - ASP.Net Core,创建具有复杂数据类型属性的模型
- javascript - 将文本颜色图标颜色更改为选定颜色 Froala Editor