How to use timeit when timing a function

前端 未结 5 1791
南旧
南旧 2020-12-16 16:41

Let me start off by saying I know almost nothing about python but have to write a program in three different languages (already done in java and c++).

I need to be a

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 17:16

    if you want something simpler

    import time
    startMillis = int(round(time.time() * 1000))
    print startMillis
    time.sleep(5) # this is your function that takes time to execute
    endMillis = int(round(time.time() * 1000))
    print endMillis
    
    timeTaken = endMillis - startMillis
    

提交回复
热议问题