3 ms·
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
by Demiurge 7y ago
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.
- Alex3917 7y agoDo 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.
- fnbr 7y agoIn 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.