发布时间:2019-08-30 09:29:51编辑:auto阅读(1930)
import time
import decimal
# text decimal_sum
print("decimal:")
start =time.time()
sum = decimal.Decimal('0')
for x in range(100):
sum += decimal.Decimal(x)
end = time.time()
# print('Running time: %s Seconds'%(end-start))
print('Running time: {} Seconds'.format(end-start))
print("===============================")
#text_int
print("sum_text")
start =time.time()
sum = 0
for x in range(100):
sum += x
end = time.time()
print('Running time: {} Seconds'.format(end-start))
print("===============================")
#print("int")
print("int")
start = time.time()
print(4.0)
end = time.time()
print('Running time: {} Seconds'.format(end-start))
print("===============================")
print("str")
start = time.time()
print("sdfgh")
end = time.time()
print('Running time: {} Seconds'.format(end-start))
print("===============================")
经由测试,print()花费时间大约是1e-6s,decimal运行花费的时间大约是int的三倍。
上一篇: 如何对python的bytes类型数据s
下一篇: Python struct模块-深入学习
47873
46438
37325
34767
29339
26002
24953
19971
19571
18065
5813°
6438°
5954°
5980°
7086°
5932°
5973°
6464°
6430°
7809°