如何解决为什么decimal.Decimal对象输出0?
我正在尝试将此算法的执行时间绘制到matplotlib图上,但是由于该函数的返回值为0,因此我很难做到。
import matplotlib.pyplot as plt
import decimal,numpy
import time
def ALoop(counter):
start_time = time.time()
sum = 1
while counter>0:
sum = sum * counter
#Decrement
counter = counter/2
timetaken = decimal.Decimal(time.time() - start_time)
print("Time taken "+ str(timetaken))
return timetaken
#Graph x axis is n of elements,y axis execution time
plt.plot([ALoop(100),ALoop(200),ALoop(300)],[100,200,300])
plt.ylabel('Execution time')
plt.xlabel('Number of elements')
plt.axis([0,300,0.1])
plt.show()
我得到的输出是:
Time taken 0
Time taken 0.0010292530059814453125
Time taken 0
我也不知道如何设置轴尺寸,
plt.axis([0,0.1])
随着值的不断变化。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。