_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Python profiling: kompletní návod

10. 08. 2024 1 min read intermediate

Python je pomalý? Možná. Ale nejdřív změřte kde.

cProfile

python -m cProfile -s cumulative app.py

snakeviz

python -m cProfile -o profile.prof app.py
snakeviz profile.prof

line_profiler

@profile
def slow_function(): …

kernprof -l -v script.py

memory_profiler

python -m memory_profiler script.py

py-spy — sampling bez overhead

py-spy record -o profile.svg – python app.py

Optimalizace

  • Generators místo lists
  • dict/set pro lookup
  • functools.lru_cache
  • numpy pro numeriku
  • multiprocessing pro CPU-bound
  • asyncio pro I/O-bound

Workflow

cProfile → snakeviz → line_profiler → optimalizace → měření znovu.

pythonperformanceprofiling
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.