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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745042059, '3.15.239.31', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/standard-library/time/index(81): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78