# Hard to beat Numba / JAX loop for generating Mandelbrot

**URL:** <https://discourse.julialang.org/t/hard-to-beat-numba-jax-loop-for-generating-mandelbrot/82725>\
**Category:** Performance\
**Tags:** fractal\
**Created:** [June 14, 2022, 6:21am UTC](https://discourse.julialang.org/t/hard-to-beat-numba-jax-loop-for-generating-mandelbrot/82725 "2022-06-14T06:21:30Z")\
**Posts on this page:** 2\
**Page:** 4

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [June 29, 2022, 11:54pm UTC](https://discourse.julialang.org/t/hard-to-beat-numba-jax-loop-for-generating-mandelbrot/82725/63 "2022-06-29T23:54:39Z")

</div>

> [@jakobnissen](#):
>
> So Numba uses 64-bit floats here, you should also use that in Julia.

Python defaults to that (well only option, except e.g. with Numpy, still the default I think), and Numba (trusting your words) but in case you missed it, in comment in code below: “need Float32 because Jax defaults to it” (also Int32).

If you want bit-identical, then of course you should use the same in both (and fma in both or neither; threading for this at least should however be ok), but for faster, Float32 (or smaller) is in general better (I’m though skeptical for this). I’m curious is there any noticeable difference in output with lower precision? Or more likely, how far would you have to zoom in to see it.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 30, 2022, 4:03am UTC](https://discourse.julialang.org/t/hard-to-beat-numba-jax-loop-for-generating-mandelbrot/82725/65 "2022-06-30T04:03:53Z")

</div>

I’m able to use KernalAbstractions.jl to solve this problem in “jax style”, where the same kernel can be used for CPU and GPU (CUDA, ROCM, oneAPI) backend:

> **[Why is JAX so fast? · Discussion #11078 · google/jax](https://github.com/google/jax/discussions/11078#discussioncomment-3053073)**
>
> I was writing a notebook to illustrate the performance trade-offs of array-oriented programming and imperative programming, which calculates the Mandelbrot set in a variety of different ways: Pytho...

[Previous page](https://discourse.julialang.org/t/hard-to-beat-numba-jax-loop-for-generating-mandelbrot/82725.md?page=3)
