[Python] datetime.now() vs time.perf_counter(): which one to use to find execution times

Discussão em 'Python' iniciado por Stack, Junho 20, 2025.

  1. Stack

    Stack Membro Participativo

    Recently I have found this question:

    Find out time it took for a python script to complete execution

    The highest voted answer suggests that for timing an execution, I should use difference in datetime.now() calls. I have seen people using time.time(), but never datetime.now() for this purpose. This video at 5:30 suggests to use time.perf_counter() (which was not mentioned in any of the answers so I added it).

    Is using datetime.now() equivalent to using time.perf_counter(), with the output having better human readability, or there are caveats?

    Continue reading...

Compartilhe esta Página