Calculating the execution time of a program

Asked

Viewed 1,333 times

1

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

  • Give examples please.

  • Like,when starting the program it starts a count(in seconds),during the course of the program I ask to read how long the program is running(Ex:80 Seconds) .

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))

exit:

--- 0.764891862869 segundos ---

There is a similar question in Soen

Browser other questions tagged

You are not signed in. Login or sign up in order to post.