是多次进行乘法还是更快地分配变量?

时间:2015-08-22 21:20:21

标签: python performance python-3.x processing-efficiency

假设我有这段代码:

foo = int(input("Number"))
bar = int(input("Number"))
for number in range(0, 10):
    if foo*bar > 0:
        print("hello")

但是,我也可以使用这段代码:

foo = int(input("Number"))
bar = int(input("Number"))
top = foo*bar
for number in range(0, 10):
    if top > 0:
        print("hello")

哪一个更快?

使用Python 3.

我意识到this问题是类似的,但是,它适用于Java,而Python可能会有所不同。另外,他们询问内存效率,而我问的是处理器效率。

0 个答案:

没有答案