Hacker News new | ask | show | jobs
by jart 610 days ago
And Numpy can't come anywhere close to the performance of my C++ code. Last time I benchmarked my CPU matrix multiplication algorithm, it went 27x faster than Numpy. Mostly because Numpy only used a single core. But this was a machine with eight cores. So my code went at least 3x faster. Moral of the story: C++ isn't something you can just foray into whenever Python is slow. It's the most complicated language there is, and the language itself is really just the tip of the iceberg of what we mean when we talk about C++. Do not underestimate the amount of devotion it takes get results out of C++ that are better than what high level libraries like Numpy can already provide you. https://justine.lol/c.jpg
2 comments

Yes but the amount of devotion is orthogonal to the language per se.

You can use Numba that uses the same LLVM clang does and write all the computation kernels yourself instead of using what Numpy provides. The only difference there would be JIT vs AOT compilation.

Or you can use Codon, that uses the same LLVM clang does and then there will be no difference at all.

Language is just an interface for a compiler.

Yeah that's what I was getting at with the tip of the iceberg thing.

You can of course choose a different tip for your iceberg.

It is nonsense that numpy can't use multiple cores. Matrix multiplication in numpy is largely C/Fortran code (BLAS, etc) where GIL can be released.

https://stackoverflow.com/questions/75029322/does-numpy-use-...