timeit返回什么时间单位?

编程入门 行业动态 更新时间:2024-10-20 05:45:58
本文介绍了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返回什么时间单位?

本文发布于:2023-11-25 15:32:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630313.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单位   时间   timeit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!