我不知道如何解释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返回什么时间单位?
发布评论