Get timer ticks in Python

后端 未结 6 711
一整个雨季
一整个雨季 2020-12-05 01:46

I\'m just trying to time a piece of code. The pseudocode looks like:

start = get_ticks()
do_long_code()
print \"It took \" + (get_ticks() - start) + \" secon         


        
6条回答
  •  有刺的猬
    2020-12-05 02:52

    What you need is time() function from time module:

    import time
    start = time.time()
    do_long_code()
    print "it took", time.time() - start, "seconds."
    

    You can use timeit module for more options though.

提交回复
热议问题