Most accurate python code timer function?

What’s the most accurate python timer function that can be used, in my case, for Windows platforms? For example; time.time(), time.clock(), java.lang.System.nanoTime(), datetime.now() ~ .microsecond, timeit, etc…?

I would like to to be precise at least to the millisecond, but after reading some on this, there can be certain factors that would make one function over the other not as precise in Windows opposed to Unix.

I’m basically wanting to get the most precise time possible that it takes a piece of code to execute (it can go fast, hence why I want it to the millisecond or better).

System.nanoTime() is the most precise, and is the only one of the above that is guaranteed to be monotonic.

1 Like