Get timer ticks in Python

后端 未结 6 725
一整个雨季
一整个雨季 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 02:33

    The time module in python gives you access to the clock() function, which returns time in seconds as a floating point.

    Different systems will have different accuracy based on their internal clock setup (ticks per second) but it's generally at least under 20milliseconds, and in some cases better than a few microseconds.

    -Adam

提交回复
热议问题