# Comparing Numba and Julia for a complex matrix computation

**URL:** <https://discourse.julialang.org/t/comparing-numba-and-julia-for-a-complex-matrix-computation/63703>\
**Category:** Performance\
**Tags:** question\
**Created:** [June 28, 2021, 3:43pm UTC](https://discourse.julialang.org/t/comparing-numba-and-julia-for-a-complex-matrix-computation/63703 "2021-06-28T15:43:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 28, 2021, 4:00pm UTC](https://discourse.julialang.org/t/comparing-numba-and-julia-for-a-complex-matrix-computation/63703/3 "2021-06-28T16:00:40Z")

</div>

> [@Ordens\_Ritter](#):
>
> I wanted to start with some code that is already highly optimized, but still at least a factor of 10 too slow to be used in production. […] I wanted to translate the code to Julia, but got stuck in the very first lines.

I should add that this is almost certainly the wrong way to go about getting performance improvements.

“Highly optimized” code in Python usually means code that is “vectorized” as much as possible — broken into a series of relatively simple array operations that can individually call fast library operations. (For example, calling `atan` on a bunch of numbers in your code above.) You can write the same sort of code in Julia, of course, but it won’t be magically faster than Numpy — there’s no secret ingredient in Julia that allows us to (for example) subtract two arrays faster.

Instead, the key to unlocking performance benefits is to realize that in Julia you don’t have to limit yourself to “vectorized library” functions for performance. For example, you perhaps shouldn’t create your array of `atan` values _at all_, but instead try to _combine_ the `atan` computation with subsequent or previous computations. (Loops are fast in Julia, and there are packages like [LoopVectorization](https://github.com/JuliaSIMD/LoopVectorization.jl) to make them even faster.)

For the same reason, micro-benchmarks of a single elementary operation (like computing a bunch of `atan` values) are unlikely to reveal much. Numpy is probably already going as fast as it is possible to go for this operation _by itself_. You really need to look at a non-trivial _sequence_ of calculations.

(If you have trouble with this, feel free to post optimized Python code that performs a dozen lines of “vectorized” calculations, along with sample inputs, and ask for help in producing an optimized Julia equivalent.)

---

_[View the full topic](https://discourse.julialang.org/t/comparing-numba-and-julia-for-a-complex-matrix-computation/63703)._
