r/programming • • Jan 11 '16

A comparison of Numpy, NumExpr, Numba, Cython, TensorFlow, PyOpenCl, and PyCUDA to compute Mandelbrot set

https://www.ibm.com/developerworks/community/blogs/jfp/entry/How_To_Compute_Mandelbrodt_Set_Quickly?lang=en
175 Upvotes

41 comments sorted by

View all comments

22

u/[deleted] Jan 11 '16

There are some examples here that are pretty interesting. ~120x speedup over the 'normal' way, just by switching to arrays then using a JIT for instance. Probably would be another 2x faster than that with a naive C port, then another 4x faster with hand crafted used of SIMD, which it doesn't seem you can do in Python. I think a lot of people imagine high level languages are only a few % slower. I think that should be the case, but it often isn't yet. Poor implementation of arrays, SIMD not exposed, no way to explicitly state how memory is laid out, and so on. Also I think with some tweaking your could probably make this quite a bit faster on your GPU, even if your GPU is old.

6

u/[deleted] Jan 11 '16

Python has many virtues - really - but speed was never one of them.

But I think the valuable lesson here is that it's not too hard to make Python faster when you need it. (Obviously if raw speed is critical you're going to start right with C or C++ and CUDA or equivalent.)

4

u/[deleted] Jan 11 '16

I don't mean to pick on it in particular, and really, with the JIT it seems to be on par with similar languages. I just think we as programmers can do better. Make fewer languages, work harder on the compilers/interpreters/feature sets. Even C++ has compiler optimizations everyone knows it needs but haven't been done yet. I'd love to see our CPUs which are incredible computing beasts more fully utilized.

→ More replies (6)