timeit返回什么时间单位? [英] What unit of time does timeit return?

查看:305
本文介绍了timeit返回什么时间单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何解释Python的timeit.timeit()函数的输出.我的代码如下:

I don't know how to interpret the output from Python's timeit.timeit() function. My code is as follows:

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.我怎么解释这个数字?

The output from this is 11.85382745500101. How do I interpret this number?

推荐答案

返回值是秒(浮点型).

这是测试运行的总时间(不计算设置),因此每个测试的平均时间是该数字除以number参数的值,默认值为100万.

It is the total time taken to run the test (not counting the setup), so the average time per test is that number divided by the number argument, which defaults to 1 million.

请参见 Time.timeit()文档:

主语句的

时间 number 次执行.这将执行一次setup语句,然后返回多次执行主语句所需的时间,以秒为单位,以浮点数为单位.该参数是循环的次数,默认为一百万.

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返回什么时间单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆