时间段返回什么时间单位?
作者:互联网
我不知道如何解释Python的timeit.timeit()函数的输出.我的代码如下:
import timeit
setup = """
import pydash
list_of_objs = [
{},
{'a': 1, 'b': 2, 0: 0},
{'a': 1, 'c': 1, 'p': lambda x: x}
]
"""
print(timeit.timeit("pydash.filter_(list_of_objs, {'a': 1})", setup=setup))
其输出是11.85382745500101.我如何解释这个数字?
解决方法:
返回值为浮点数秒.
它是运行测试所花费的总时间(不计算设置),因此每个测试的平均时间是该数字除以number参数所得到的值(默认为100万).
参见Time.timeit()
documentation:
Time number executions of the main statement. This executes the setup statement once, and then returns the time it takes to execute the main statement a number of times, measured in seconds as a float. The argument is the number of times through the loop, defaulting to one million.
标签:timeit,python-3-4,python,python-3-x 来源: https://codeday.me/bug/20191010/1886492.html