[英]What is the 'unit of output time' when default_timer is used from timer module?
I'm trying to find the time taken by this program ("Fibonacci series") to run.我试图找出这个程序(“斐波那契数列”)运行所花费的时间。
from timeit import default_timer as timer
n=int(input())
start = timer()
li=[0,1,1]
if n==1:
print(li[0])
elif n==2 or n==3:
print(li[1])
else:
for i in range(n-3):
x=li[-1]+li[-2]
li.append(x)
print(li[-1])
print("{}".format(timer()-start))
I give the input 100
and I get the output as我给输入
100
我得到 output 为
218922995834555169026
0.0004896000000371714
The first line is the Fibonacci answer and the second line is the time taken, I want to know what is the unit of this time?第一行是斐波那契答案,第二行是所用时间,我想知道这个时间的单位是什么? '0.0004896000000371714' what this value means?
'0.0004896000000371714' 这个值是什么意思?
It is in seconds;以秒为单位; see docs: the default timer usually points to the time.perf_counter function.
请参阅文档:默认计时器通常指向time.perf_counter function。 You can use time.perf_counter_ns for nanoseconds.
您可以使用time.perf_counter_ns纳秒。
If you inspect timer
you will see it is <function time.perf_counter>
or some similar result.如果您检查
timer
,您会看到它是<function time.perf_counter>
或一些类似的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.