4 ms·
Speaking of python performance, I recently benchmarked "numpy vs js" matrix multiplication performance, and was surprised to find js significantly outperforming
by raphaelrk 4y ago
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.js: ~6.00ms
tfjs cpu: ~244.65ms
mathjs: ~3469.00ms
c
accelerate.h: ~.06ms
Source here: https://github.com/raphaelrk/matrix-mul-test https://github.com/raphaelrk/matrix-mul-test
- netheril96 4y agoNumpy runs on CPU. Tfjs runs on GPU. Not a fair comparison.
- raphaelrk 4y agoYou'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.
- qeternity 4y agoPeople don’t reach for numpy because it’s the absolute fastest…
- raphaelrk 4y agoWhat I meant was I expected numpy to be faster than the js libraries I was testing, simply because people use it so much more, for real "scientific computing" work. And indeed it is very fast given it only uses the CPU, but that still leaves its matrix multiplication as ~100x slower than what my mac is capable of.
- psyklic 4y agoIt adds a great deal of complexity (and often user frustration) for a Python package to support both CPU and GPGPU.
- dhasso 4y agoFor that, you can use cupy[0], PyTorch[1] or Tensorflow[2]. They all mimic the numpy's API with the possibility to use your GPU. [0] https://cupy.dev/ https://cupy.dev/ [1] https://pytorch.org/ https://pytorch.org/ [2] https://www.tensorflow.org/ https://www.tensorflow.org/
- sampo 4y agoTensorFlow.js matrices are immutable, which puts more restrictions on your programming style that standard Numpy. You cat get immutable, GPU-enhanced matrices for Python, too.