【发布时间】:2019-01-06 17:32:45
【问题描述】:
假设您有以下数据类型(作为参数填充的数字):
- 整数 权重
- 浮动 高度
目标是计算 body-mass index 看起来像 23.13 等...
bodyMassIndex = 体重/身高^2
我想使用 bmi 更像是例如将 bmi (float) 转换为 int 或将 bmi 除以模数等...
是先保存bmi再在其他计算中使用变量(选项a)还是在其他计算中再次进行公式计算(选项b)在计算速度方面更快(选项b)?
选项 A:
**bmi** = weight / height^2
OtherCalculation = **bmi** % 10
...
选项 B:
bmi = weight / (height^2)
OtherCalculation = (weight / height^2) % 10
OtherOtherCalculation = (weight / height^2) * 100
...
编辑:我正在用 Python 编写
【问题讨论】:
-
你用什么语言工作?
-
我正在使用 Python
标签: python performance optimization computation-theory