Labs ICT
Pro Login

Time

1 min read | Python Tutorial

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

Sleep with time.sleep()

time.sleep(seconds) pauses execution for the given number of seconds. Useful for rate-limiting, animation delays, or waiting between retries.

import time

print("Starting...")
time.sleep(2)
print("Two seconds later!")

Timing Code with perf_counter()

time.perf_counter() returns a high-resolution timestamp. Call it before and after a block of code to measure elapsed time precisely.

import time

start = time.perf_counter()
total = sum(range(1_000_000))
end = time.perf_counter()

print(f"Sum: {total}")
print(f"Time: {end - start:.4f} seconds")