How to measure time taken between lines of code in python?

前端 未结 7 923
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 11:00

So in Java, we can do How to measure time taken by a function to execute

But how is it done in python? To measure the time start and end time between lines of codes?

7条回答
  •  旧时难觅i
    2020-12-04 11:58

    You can try this as well:

    from time import perf_counter
    
    t0 = perf_counter()
    
    ...
    
    t1 = perf_counter()
    time_taken = t1 - t0
    

提交回复
热议问题