时间单位是什么?

2024-06-01 21:38:56 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: oflambda函数代码importsetup数字filter
1条回答
网友
1楼 · 发布于 2024-06-01 21:38:56

返回值为秒(浮点)。

这是运行测试(不包括设置)所用的总时间,因此每个测试的平均时间是这个数字除以number参数,默认为100万。

请参见^{} 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.

相关问题 更多 >