How to use python timeit when passing variables to functions?

后端 未结 5 767
迷失自我
迷失自我 2020-12-07 09:37

I\'m struggling with this using timeit and was wondering if anyone had any tips

Basically I have a function(that I pass a value to) that I want to test the speed of

5条回答
  •  独厮守ぢ
    2020-12-07 09:43

    A note for future visitors. If you need to make it work in pdb debugger, and superMegaIntenseFunction is not in the global scope, you can make it work by adding to globals:

    globals()['superMegaIntenseFunction'] = superMegaIntenseFunction
    timeit.timeit(lambda: superMegaIntenseFunction(x))
    

    Note that the timing overhead is a little larger in this case because of the extra function calls. [source]

提交回复
热议问题