Quick Answer
Profile Python applications: cProfile (built-in, minimal overhead): python -m cProfile -o output.prof script.py. Visualize with snakeviz output.prof. For production: py-spy (sampling profiler - attach to running process without code changes). Line-level: kernprof -l -v script.py with @profile decorator. Memory: python -m memory_profiler with @profile. Always profile first, optimize second.
Answer
Use cProfile, timeit, and line profiling. Identify slow functions and optimize algorithms. Apply vectorization and efficient data structures.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.