【发布时间】:2013-01-02 05:28:20
【问题描述】:
我做了这个测试
import time
def test1():
a=100
b=200
start=time.time()
if (a>b):
c=a
else:
c=b
end=time.time()
print(end-start)
def test2():
a="amisetertzatzaz1111reaet"
b="avieatzfzatzr333333ts"
start=time.time()
if (a>b):
c=a
else:
c=b
end=time.time()
print(end-start)
def test3():
a="100"
b="200"
start=time.time()
if (a>b):
c=a
else:
c=b
end=time.time()
print(end-start)
并得到结果
1.9073486328125e-06 #test1()
9.5367431640625e-07 #test2()
1.9073486328125e-06 #test3()
执行时间相似。是的,使用整数代替字符串会减少存储空间,但执行时间呢?
【问题讨论】:
-
你想知道的执行时间是多少?
-
@martineau:我会理解为什么通常说使用整数比使用字符串更好; GarethRees 给了我一个很好的方向
标签: python time python-3.x comparison