Accurate timing of functions in python

后端 未结 7 1058
一向
一向 2020-11-30 19:23

I\'m programming in python on windows and would like to accurately measure the time it takes for a function to run. I have written a function \"time_it\" that takes another

7条回答
  •  长情又很酷
    2020-11-30 19:36

    Similar to @AlexMartelli's answer

    import timeit
    timeit.timeit(fun, number=10000)
    

    can do the trick.

提交回复
热议问题