How to use timeit module

后端 未结 14 2816
猫巷女王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条回答
  •  余生分开走
    2020-11-22 08:06

    for me, this is the fastest way:

    import timeit
    def foo():
        print("here is my code to time...")
    
    
    timeit.timeit(stmt=foo, number=1234567)
    

提交回复
热议问题