0

Why Is My Code So Slow? A Guide to Py-Spy Python Profiling

https://towardsdatascience.com/why-is-my-code-so-slow-a-guide-to-py-spy-python-profiling/(towardsdatascience.com)
Slow-running but functional code can be a major bottleneck in data science workflows. This guide introduces `py-spy`, a sampling profiler for Python, as a tool to diagnose these performance issues without significantly slowing down the code. Using an example of calculating flight distances, it demonstrates how to run `py-spy` and interpret its icicle graph output to identify the most time-consuming functions. The analysis reveals that a `pandas.iterrows()` loop is the primary bottleneck, and optimizing the script with a vectorized NumPy function dramatically reduces the execution time.
0 pointsby hdt22 hours ago

Comments (0)

No comments yet. Be the first to comment!

Want to join the discussion?