4 ms·
NumPy vs. BLAS: Losing 90% of Throughput
- Bostonian 3y agoThere was a 2022 paper along these lines, "The Linear Algebra Mapping Problem. Current State of Linear Algebra Languages and Libraries", with a preprint at https://arxiv.org/abs/1911.09421 https://arxiv.org/abs/1911.09421
- theamk 3y agoThat paper shows much more reasonable results: numpy was either similar performance to hand-code C (when the right operation was chosen), or about 3x slower when it was not. Nothing as crazy as the blog post describes. Shows you really have to know how to use tools properly to get the performance you want.
- theamk 3y agoThis is on "1536-dimensional vectors", which here means a single vector with 1536 elements, which is really small. In numpy, the way you get performance is to work with much larger blocks, so the Python's overhead is spread across much larger number of elements. In other words, a loop like this is a huge red flag in any sort of numpy code that is supposed to be performant [0]: """Wrap a function to apply it row-wise to rows of two matrices.""" def wrapped(A, B): for i in range(A.shape[0]): baseline_func(A[i], B[i]) return wrapped [0] https://github.com/ashvardanian/SimSIMD/blob/3e51bacb1b74a7ed3fa7bb037162276047192bab/python/bench.py#L196 https://github.com/ashvardanian/SimSIMD/blob/3e51bacb1b74a7e...
- ashvardanian 3y agoThat's precisely my point - the NumPy+Python overhead is quite costly for fine-grained processing :) PS: Those `wrapped` functions aren't used for any reported numbers in the article.