3 ms·
I was doing a Hacker Rank puzzle yesterday in Python and after I optimised it, it still timed out on one input. Looked at the chat, and saw a comment "just run
by sammorrowdrums 5y ago
I was doing a Hacker Rank puzzle yesterday in Python and after I optimised it, it still timed out on one input. Looked at the chat, and saw a comment "just run it with PyPy" and naturally it then passed all parts.
It's easy to forget that CPython is not that optimised generally, but as soon as you need to deal with algorithms it is lacking often.
I think even that the fact there are so many C implementations in libraries shows that the lack of optimisation for the sake of clean compiler code manifests as a readability / complexity issues elsewhere.
- FartyMcFarter 5y ago> It's easy to forget that CPython is not that optimised generally, "Not that optimised" is actually an understatement. In my experience, CPU-heavy code typically becomes 10-100x faster if you port it from Python to a language like C (without even trying to be clever or using SIMD assembly).
- stevesimmons 5y agoOften you can put a "@numba.jit" decorator at the top of a calc-heavy function, and reclaim a good portion of C's performance. It is so simple it is definitely worth trying. I did it for Bloom tree implementation, and got to within around 3x of the C code it replaced.