关于python中timeit模块的问题
我有一个关于python中timeit模块的问题,该模块用于确定一段代码执行所需的时间。
t = timeit.Timer("foo","from __main__ import foo")
str(t.timeit(1000))
上面代码中参数 1000 的含义是什么?
I have a question about the timeit module in python, which is used to determine the time it takes for a piece of code to execute.
t = timeit.Timer("foo","from __main__ import foo")
str(t.timeit(1000))
What is the meaning of the argument 1000 in the above code ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自文档:
From the documentation:
正如记录的,数字表示 timeit 应执行的次数指定的程序。
由于由于缓存,前几次执行可能会明显变慢,并且各个执行时间可能会有很大差异,因此更多的计时运行(即更高的值)将产生更精确的结果,但也会花费更长的时间。
As documented, the number indicates the number of times timeit should execute the specified program.
Since the first few executions can be significantly slower due to caching, and individual execution times may vary wildly, more timing runs (i.e. a higher value) will yield a more precise result, but also take longer.
本着授人以鱼的精神,问问Python:
In the spirit of teaching a man to fish, just ask Python: