timeitreturn是什么时间单位?

What unit of time does timeit return?

我不知道如何解释 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。我该如何解释这个数字?

return 值是 秒作为浮点数

它是 到 运行 测试的总时间(不包括设置),因此每次测试的平均时间是该数字除以 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.