1
likuku 2016-04-04 11:51:25 +08:00
main() 最后一行,加个 break 呢?
|
2
likuku 2016-04-04 11:58:29 +08:00
你何不将 def mian(): 改名为 def test_main():
if __name__ =="__main__": #main() #运行时间计时 import timeit times1=timeit.Timer("test_main()","from __main__ import test_main") print(times1.timeit(10000)) |
3
omg21 OP 不行啊,改名以后问题依旧, break 只能是用于循环语句中,加入后会提示语法错误。
|
4
omg21 OP 刚才又试了一下,把这三行去掉,问题就不存在了,程序只运行一遍即结束,看来问题是出在 timeit 的调用上。
import timeit times1=timeit.Timer("test_main()","from __main__ import test_main") print(times1.timeit(10000)) |
5
sNullp 2016-04-04 12:48:44 +08:00
LMGTFY: https://docs.python.org/3.0/library/timeit.html
Timer.timeit([number=1000000]) 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. The main statement, the setup statement and the timer function to be used are passed to the constructor. |
6
omg21 OP print(times1.timeit(10000))
原来总是出在 10000 上,把 10000 改成 1 程序会运行 2 遍,改成 0 会运行 1 遍,但是时间不对。 |