Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

These are all trivial micro-optimizations.

“If you want your code to run faster, you should probably just use PyPy.” — Guido van Rossum

https://pypy.org/



Until you need a module that requires the C api: at which point pypy becomes useless


They're developing a replacement API to address those issues.

https://morepypy.blogspot.com/2019/12/hpy-kick-off-sprint-re...


That is when you see the light and switch to Julia ;-)


Cython is alternative option for speeding up specific parts of code. There is also numba and hope modules providing JIT decorators.

Personally, I’ve tried pypy without issues, out of curiosity, but in about 15 years of using python never ran into python code as being the performance bottleneck. There are too highly performant modules for everything.


Do you have advice for finding code snippets that would most benefit from being re-written in C and called with Cython? I know how to find slow functions in Python, but obviously not every slow function will be a good candidate for rewriting.


In my experience, most pure python code will be 10 to 100x faster if it’s rewritten in C++. So I just profile it as usual using cProfile, try to make algorithmic improvements (eg caching) and then, if I need another order of magnitude, rewrite it in C++.

So basically anything where the hot path is in pure Python, rather than a standard library method.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: