How to use timeit module

后端 未结 14 2825
猫巷女王i
猫巷女王i 2020-11-22 07:36

I understand the concept of what timeit does but I am not sure how to implement it in my code.

How can I compare two functions, say insertion_sort

14条回答
  •  萌比男神i
    2020-11-22 08:11

    import timeit
    
    
    def oct(x):
       return x*x
    
    
    timeit.Timer("for x in range(100): oct(x)", "gc.enable()").timeit()
    

提交回复
热议问题