#1
[Image: python-performance-checklist-banner.png]

Do not optimize from a guess. Measure the real workload, find the bottleneck, make one change, and measure again.

1. Reproduce the slowdown
Use the same input size, environment, Python version, and configuration each time. A benchmark that changes between runs cannot tell you whether the code improved.

2. Record a baseline
Measure the whole operation before changing anything. Keep the result and the command so you can compare it with the next run.

3. Use timeit for small snippets
Code:
python -m timeit -s "items = list(range(1000))" "sum(items)"
The timeit module repeats small statements and avoids several common timing mistakes.

4. Profile the full program
Code:
python -m cProfile -s cumulative app.py
Start with functions that have high cumulative time or are called far more often than expected.

5. Separate waiting from computing
A slow script may be waiting on files, databases, APIs, DNS, or network responses. Faster Python code will not fix a slow external dependency.

6. Remove repeated work
Look for files opened inside loops, repeated parsing, duplicate database queries, repeated conversions, and values that can be calculated once and reused.

7. Check the data structure
Use a set for repeated membership checks, a dictionary for key-based lookup, and generators when the entire result does not need to stay in memory. Choose based on the workload, not habit.

8. Prove the improvement
Run the same benchmark several times, compare typical results, and rerun tests to confirm that faster code still produces the correct output.

Quick performance note
Code:
Python version:
Operating system:
Input size:
Baseline command:
Baseline result:
Profiler hotspot:
Change made:
New result:
Correctness test:

Useful references
- Python documentation: timeit
- Python documentation: cProfile and profile
- Python Logging HOWTO

if this helped you, a like is appreciated — wishing you the best