【发布时间】:2019-05-02 17:31:42
【问题描述】:
我有一小段代码需要运行很长时间。我想知道我使用的变量名称的长度是否会改变程序执行的速度。这是一个用 Python 编写的非常简单的示例。
程序 A
x = 1
while not x == 0:
print('message')
程序 B
xyz = 1
while not xyz == 0:
print('message')
如果我在两台相同的机器上运行程序 A 和程序 B 30 年,程序 A 打印“消息”的次数会比程序 B 多。
【问题讨论】:
-
过早的优化问题,让你的代码可读而不是担心这些事情
标签: python performance naming-conventions naming-containers