There's some genuinely interesting tips in here, but #10 is for sure just padding so they could call the article "10 Hacks" haha. Everything else is at least somewhat Python specific, but "Hack 10: Avoid repeated function calls in loops" is just applicable to anything.
Performance hacks for faster Python code
11–20 of 65 posts
Re: Performance hacks for faster Python code
#12Re: Performance hacks for faster Python code
#13Re: Performance hacks for faster Python code
#14There's some genuinely interesting tips in here, but #10 is for sure just padding so they could call the article "10 Hacks" haha. Everything else is at least somewhat Python specific, but "Hack 10: Avoid repeated function calls in loops" is just applicable to anything.
Re: Performance hacks for faster Python code
#15Some helpful guidelines, but it's 2025 and people still use time.time and no stats with their benchmarks :( In general I feel like these kind of benchmarks might change for each python version, so some caveats might apply.
Re: Performance hacks for faster Python code
#16Some of these are pretty nice python tricks though.
Re: Performance hacks for faster Python code
#17Re: Performance hacks for faster Python code
#18Maybe also knowing when not to use python, or finding a solution in python that uses C/rust/etc underneath.
Re: Performance hacks for faster Python code
#19> Copying large objects like lists […] can be costly in both time and memory. > modify[ing] objects in place […] improves performance by avoiding the overhead of allocating and populating new structures. AFAIK the poor performance of list copies (demonstrated in the article by a million-element list taking 10ms) doesn’t come from memory allocation nor from copying the contents of the list itself (in this case, a mill…
Which means, eventually, designing your data structures so you generally have two types of structures: one which isn't full of pointers, and one which mostly is.
Re: Performance hacks for faster Python code
#20Maybe also knowing when not to use python, or finding a solution in python that uses C/rust/etc underneath.