Search notes:

Python standard library: time

sleep

time.sleep(secs) stops execution of the script for secs seconds.
#!/usr/bin/python3

import time

t_start = time.time()
print("Time going to sleep for four seconds.")
time.sleep(4)
print("Just woke up, after {:f} seconds".format(time.time() - t_start))
Github repository about-python, path: /standard-library/time/sleep.py

perf_counter

time.perf_counter allows to quickly measure the time something takes.
#!/usr/bin/python3

import time

def doSomething():
    ret = 0
    for i in range(0, 100):
        ret += i**i

    return ret

t0 = time.perf_counter()
print(doSomething())
t1 = time.perf_counter()

tExec = t1 - t0

print(f"Execution of doSomething took {tExec:.7f} seconds.")
Github repository about-python, path: /standard-library/time/perf_counter.py
For more accurate timings, the timeit module should probably be used.

See also

standard library

Index