fortran - Fortran - 变量的使用
问题描述
编译后,使用额外变量引用数组的某些部分与持续索引它在执行速度/效率上是否有任何差异?例如:
... some code that defines/populates "array" here ...
item3 = array(3)
subroutine1(item3, ...)
...
subroutine2(item3, ...)
...
some equation using item3
...
subroutine3(item3, ...)
... etc
相对
... some code that defines/populates "array" here ...
subroutine1(array(3), ...)
...
subroutine2(array(3), ...)
...
some equation using array(3)
...
subroutine3(array(3), ...)
... etc
另一个例子可能是创建一个可以跳过的变量。例如:
x = b / c
y = x + 1 ! This is the only use of x
对比
y = (b / c) + 1
这些在编译时是否等效,或者第一个会因为创建变量“x”而变慢?如果您多次需要“x”的值,那么我认为第一个会更快,因为它可以避免多次进行除法。但只有 1 或 2 次使用,我不确定。
解决方案
推荐阅读
- python - 如何让我的 python 代码更有效
- google-chrome-extension - Yandex 浏览器是否支持从 google chrome 网上商店付费扩展运行?
- keras - 无法保存和加载模型
- android - 无法为 AOSIP 构建目标:在system/core/base/cmsg.cpp:36:21 中使用未声明的标识符“PAGE_SIZE”:
- javascript - 如何在 Nestjs 中使用 globalPipse 进行自定义响应
- python - 如果标题已存在于文本文件中,如何替换列表中的项目?
- c# - 我无法从基类 c# 访问变量
- aws-lambda - 如何在 VTL 模板中附加响应标头
- c - 多次将相同的数字添加到C中的空数组
- mysql - 将两个不同表中的两列相乘,并使用触发器将它们设置到另一个表中