The Mandelbrot Set: Numba vs C

Having demonstrated how to call C from python, we can investigate whether numba really is as fast as C when both are available. So the C Mandelbrot column function has been rewritten to use C's double precision data type, and the python version has also been rewritten to use real variables.



And the module needs to be built with

python3 build_ext --inplace

after downloading the above three files into the same directory


The time taken to display the initial set is much longer with the numba version, as it needs to compile the function the first time it is called.

Picking an example needing a little more time that the default full set, such as "Four Spirals" from the gallery,

Four spirals

(-0.7474617+0.0788155i) to (-0.7474523+0.0788249i)

the advantage to C appears to be around 1 to 2%. Quite negligible.

Not too surprising. The C and python code look almost identical, and so the two different compilers ought to be able to produce similarly-efficient code for them.

On the other hand, C can be used in cases where numba cannot, and there may be more complicated cases in which C gains.