Calculate the execution time of a program

1

How do I add a timer at the beginning of the program and during the execution can I read the time elapsed from the start of the program in seconds?

    
asked by anonymous 02.08.2018 / 20:16

1 answer

4

Just use the library time

import time

tempo_inicial = time.time()

funcao() # chame a função que deseja medir o tempo de execução aqui

print("--- %s segundos ---" % (time.time() - tempo_inicial))

output:

--- 0.764891862869 segundos ---

There's a similar question in SOen

    
02.08.2018 / 20:29