2
$\begingroup$

I want to print a timer in the console to optimize my script and see how long it takes to run the script.

$\endgroup$
3
$\begingroup$

This is one of the fastest way I know:

import time
import random

then = time.time() #Time before the operations start

#DO YOUR OPERATIONS HERE

now = time.time() #Time after it finished

print("It took: ", now-then, " seconds")

time.time() Will give you the current time in seconds. There are other way of doing it, but this is one of the best. I have always used this and it gave me no problem at all.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.