我不知道如何解释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.