Speaking of python performance, I recently benchmarked "numpy vs js" matrix multiplication performance, and was surprised to find js significantly outperforming numpy. For multiplying two 512x512 matrices: python numpy: ~3.30ms numpy with numba: ~2.90ms node tfjs: ~1.00ms gpu.js: ~4.00ms ndarray: ~118.00ms vanilla loop: ~138.00ms mathjs: ~1876.00ms browser tfjs webgpu: ~.16ms tfjs webgl: ~.76ms tfjs wasm: ~2.51ms gpu…
Making Python fast – Adventures with mypyc
71–80 of 95 posts
Re: Making Python fast – Adventures with mypyc
#72Earlier quoted context omitted.
Numpy runs on CPU. Tfjs runs on GPU. Not a fair comparison.
You're right, it's not a fair comparison -- I think it's still interesting though, since numpy is the standard people would reach for, which made me think it would be the fastest / use the GPU. I expect a python library that uses the GPU would be just as fast as the others.
Re: Making Python fast – Adventures with mypyc
#73Earlier quoted context omitted.
Syntactically Python is great. Runtime though, its not. Its fast to code in - that is all.
Agreed. I'm past the "it's like writing pseudo-code - so cool!" honeymoon phase and onto the "some sort of static typing is actually pretty useful" as a developer.
Re: Making Python fast – Adventures with mypyc
#74Earlier quoted context omitted.
Numpy runs on CPU. Tfjs runs on GPU. Not a fair comparison.
You're right, it's not a fair comparison -- I think it's still interesting though, since numpy is the standard people would reach for, which made me think it would be the fastest / use the GPU. I expect a python library that uses the GPU would be just as fast as the others.
[0] https://cupy.dev/ [1] https://pytorch.org/ [2] https://www.tensorflow.org/
Re: Making Python fast – Adventures with mypyc
#75Earlier quoted context omitted.
Agreed. I'm past the "it's like writing pseudo-code - so cool!" honeymoon phase and onto the "some sort of static typing is actually pretty useful" as a developer.
Good thing is that python3 provides typing.
Re: Making Python fast – Adventures with mypyc
#76Have they cleaned up Python's packaging/dependency problem yet?
Re: Making Python fast – Adventures with mypyc
#77Earlier quoted context omitted.
No such thing as a constant in Python. You can optionally name a variable in uppercase to signal to others that it should be, but that's about it. You can write a new compiler if you'd like, as detailed on this page. But CPython doesn't work that way and 99% of the ecosystem is targeted there. There is some work on making more assumptions as it runs, now that the project has funding. This is about where my off-top-of…
> No such thing as a constant in Python. You can optionally name a variable in uppercase to signal to others that it should be, but that's about it. Yeah that’s the point - the JIT takes that capitalisation as a hint to treat it as a true constant and bake the value in until it’s redefined. This is all solved stuff and isn’t a barrier to implementing a powerful JIT for Python if someone wanted to.
Re: Making Python fast – Adventures with mypyc
#78Earlier quoted context omitted.
> No such thing as a constant in Python. You can optionally name a variable in uppercase to signal to others that it should be, but that's about it. Yeah that’s the point - the JIT takes that capitalisation as a hint to treat it as a true constant and bake the value in until it’s redefined. This is all solved stuff and isn’t a barrier to implementing a powerful JIT for Python if someone wanted to.
It's solved stuff in languages other than Python. Many groups even at google have tried and failed.
Re: Making Python fast – Adventures with mypyc
#79Earlier quoted context omitted.
Good thing is that python3 provides typing.
Optional type hints are not the same at all.
This is miles ahead of having to struggle with getting types correct in C++ before you even have anything resembling a workable solution.
Re: Making Python fast – Adventures with mypyc
#80Earlier quoted context omitted.
Optional type hints are not the same at all.
No, its better. You can build the code first, test that it functions as expected, then add types, then compile it. This is miles ahead of having to struggle with getting types correct in C++ before you even have anything resembling a workable solution.