timeitEasy Examples

Measure execution time of small code snippets

Getting started with timeit

Basic import and usage of the timeit module.

python
import timeit

# Time a simple expression
t1 = timeit.timeit("sum(range(100))", number=10000)
t2 = timeit.timeit("[x**2 for x in range(100)]", number=10000)
print(f"sum(range(100)): {t1:.4f}s")
print(f"List comp: {t2:.4f}s")

The timeit module is part of Python's standard library. Measure execution time of small code snippets.

Common timeit operations

Frequently used functions from the timeit module.

python
# More timeit examples
import timeit

print(f"timeit module loaded successfully")
print(f"Location: {timeit.__name__}")
print(f"Has {len(dir(timeit))} attributes")

These are the most commonly used features of the timeit module.

Want to try these examples interactively?

Open Easy Playground