Telegram Group & Telegram Channel
📊 Шпаргалка по Python-профайлингу: как найти узкие места в коде

Разбираем 4 мощных инструмента для анализа производительности и памяти в Python.

🧠 `cProfile` — встроенный профайлер времени

Показывает, сколько времени тратится на каждую функцию
Идеально для быстрого анализа


python -m cProfile your_script.py


Форматированный вывод с pstats:


python -m cProfile -o result.prof your_script.py
python -m pstats result.prof


Для Jupyter:


%load_ext cprofile
%cprofile some_function()


🐍 py-spy — суперлёгкий sampling-профайлер

Не требует изменений в коде
Работает с чужими процессами
Без тормозов, можно запускать в проде


py-spy top --pid <PID>
py-spy record -o profile.svg -- python your_script.py


👉 Показывает flame graph: удобная визуализация bottleneck-функций.

🔥 `Scalene` — профайлинг CPU, памяти и аллокаций

Отслеживает:
- сколько времени тратит CPU
- где происходят аллокации
- сколько памяти реально используется


pip install scalene
scalene your_script.py


👉 Выделяет проблемные строки, показывает выделение памяти по строчкам кода, а не только по функциям.

🧮 `memory_profiler` — анализ использования памяти

Показывает, сколько памяти потребляет каждая строка
Полезен для data science скриптов


pip install memory-profiler


Добавь декоратор:


from memory_profiler import profile

@profile
def my_func():
...


Запуск:


python -m memory_profiler your_script.py


💡 Как выбрать?

| Инструмент | Что профилирует | Подходит для |
|--------------------|----------------------|------------------------------|
| `cProfile` | Время (встроенно) | Быстрый старт, базовый анализ |
| `py-spy` | Время (sampling) | Прод, чужие процессы, flame graphs |
| `Scalene` | Время + память + аллокации | Глубокий анализ по строкам |
| `memory_profiler` | Только память | Data science, отладка RAM |



tg-me.com/pro_python_code/1823
Create:
Last Update:

📊 Шпаргалка по Python-профайлингу: как найти узкие места в коде

Разбираем 4 мощных инструмента для анализа производительности и памяти в Python.

🧠 `cProfile` — встроенный профайлер времени

Показывает, сколько времени тратится на каждую функцию
Идеально для быстрого анализа


python -m cProfile your_script.py


Форматированный вывод с pstats:


python -m cProfile -o result.prof your_script.py
python -m pstats result.prof


Для Jupyter:


%load_ext cprofile
%cprofile some_function()


🐍 py-spy — суперлёгкий sampling-профайлер

Не требует изменений в коде
Работает с чужими процессами
Без тормозов, можно запускать в проде


py-spy top --pid <PID>
py-spy record -o profile.svg -- python your_script.py


👉 Показывает flame graph: удобная визуализация bottleneck-функций.

🔥 `Scalene` — профайлинг CPU, памяти и аллокаций

Отслеживает:
- сколько времени тратит CPU
- где происходят аллокации
- сколько памяти реально используется


pip install scalene
scalene your_script.py


👉 Выделяет проблемные строки, показывает выделение памяти по строчкам кода, а не только по функциям.

🧮 `memory_profiler` — анализ использования памяти

Показывает, сколько памяти потребляет каждая строка
Полезен для data science скриптов


pip install memory-profiler


Добавь декоратор:


from memory_profiler import profile

@profile
def my_func():
...


Запуск:


python -m memory_profiler your_script.py


💡 Как выбрать?

| Инструмент | Что профилирует | Подходит для |
|--------------------|----------------------|------------------------------|
| `cProfile` | Время (встроенно) | Быстрый старт, базовый анализ |
| `py-spy` | Время (sampling) | Прод, чужие процессы, flame graphs |
| `Scalene` | Время + память + аллокации | Глубокий анализ по строкам |
| `memory_profiler` | Только память | Data science, отладка RAM |

BY Python RU


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/pro_python_code/1823

View MORE
Open in Telegram


Python RU Telegram | DID YOU KNOW?

Date: |

That growth environment will include rising inflation and interest rates. Those upward shifts naturally accompany healthy growth periods as the demand for resources, products and services rise. Importantly, the Federal Reserve has laid out the rationale for not interfering with that natural growth transition.It's not exactly a fad, but there is a widespread willingness to pay up for a growth story. Classic fundamental analysis takes a back seat. Even negative earnings are ignored. In fact, positive earnings seem to be a limiting measure, producing the question, "Is that all you've got?" The preference is a vision of untold riches when the exciting story plays out as expected.

Telegram announces Anonymous Admins

The cloud-based messaging platform is also adding Anonymous Group Admins feature. As per Telegram, this feature is being introduced for safer protests. As per the Telegram blog post, users can “Toggle Remain Anonymous in Admin rights to enable Batman mode. The anonymized admin will be hidden in the list of group members, and their messages in the chat will be signed with the group name, similar to channel posts.”

Python RU from us


Telegram Python RU
FROM USA