Ir al contenido principal

Stop measuring time with time.clock() in Python3

If we read the time.clock() documentation (https://docs.python.org/3/library/time.html#time.clock):

Deprecated since version 3.3: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.

I use time.perf_counter, but feel free to use time.process_time if fits for your requirements. The main difference they have are:

  • time.perf_counter()
    • It does include time elapsed during sleep and is system-wide.

  • time.process_time()
    • It does not include time elapsed during sleep. It is process-wide by definition.

Comentarios