3 ms·
The thing with Python is it's usually pretty easy to optimise quite impressively. E.g. random example: Sprinkle some cdef's in your python and suddenly you're
by CraigJPerry 5y ago
The thing with Python is it's usually pretty easy to optimise quite impressively.
E.g. random example:
Sprinkle some cdef's in your python and suddenly you're faster than c++
https://github.com/luizsol/PrimesResult https://github.com/luizsol/PrimesResult
https://github.com/PlummersSoftwareLLC/Primes/blob/drag-race/PrimeCython/solution_1/PrimeCY_32.pyx https://github.com/PlummersSoftwareLLC/Primes/blob/drag-race...
25.8 seconds down to 1.5
- stavros 5y agoApparently mypyc does the same if you have types in your code, though I've never used it.
- Jensson 5y agoI've tried cython and it isn't competitive with C in real world cases. Cherry picking a case where it is competitive doesn't help your case. Its performance tend to be around the level of Java, another language people say is competitive or faster than C++ but in practice C++ is still twice faster than Java in most cases. Still, getting Java level performance out of python is a huge improvement and should be enough for most cases.
- CraigJPerry 5y agoAhh my point was more that you can score a 17x performance boost with minimal effort rather than any absolute performance advantage over c++. For a c++ comparison python would be much better pointing out the productivity advantage it has over the notoriously low productivity of c++ development - rather than competing on execution performance.
- PartiallyTyped 5y agoThere is also numba, which is very impressive in its own right, and also pypy, which supports features up to Python 3.7. Some may consider Jax, and its XLA compiler, but unless you require gradients, numba will be significantly faster, an instance of this is available here [1]. XLA runs on a higher level than LLVM and therefore can't achieve the same optimizations as numba does using the latter. IIRC numba also has a Python to Cuda compiler, which is also very impressive. [1] https://github.com/scikit-hep/iminuit/blob/develop/doc/tutorial/automatic_differentiation.ipynb https://github.com/scikit-hep/iminuit/blob/develop/doc/tutor...