# Why I still recommend Julia: how 300 lines of Julia code being 1000x faster than MATLAB's C Mex codes

**URL:** https://discourse.julialang.org/t/why-i-still-recommend-julia-how-300-lines-of-julia-code-being-1000x-faster-than-matlabs-c-mex-codes/97842
**Category:** Performance
**Created:** [April 24, 2023, 7:35am UTC](https://discourse.julialang.org/t/why-i-still-recommend-julia-how-300-lines-of-julia-code-being-1000x-faster-than-matlabs-c-mex-codes/97842 "2023-04-24T07:35:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JohnnyChen94](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnnychen94/32/29979_2.png) [@JohnnyChen94](https://discourse.julialang.org/u/JohnnyChen94)
#### Post date: [April 24, 2023, 7:35am UTC](https://discourse.julialang.org/t/why-i-still-recommend-julia-how-300-lines-of-julia-code-being-1000x-faster-than-matlabs-c-mex-codes/97842/1 "2023-04-24T07:35:34Z")

</div>

I believe this is an excellent real-world example to showcase Julia’s superiority.

[GaloisFieldNumbers](https://github.com/Suzhou-Tongyuan/GaloisFieldNumbers.jl) is a reference (snapshotted) implementation that shows the beauty of Julia in 300 lines of code. It was released a few months ago in the Chinese community and was never posted here.

In summary:

- it’s about 300 lines of code, written in about 2-3 days.
- on CPU, it’s 1000 times faster than MATLAB’s C codes by adopting two key designs:
  - **composability** : scalar struct design to reuse the array implementation
  - **generated function** : dynamic generation of lookup-table (used by multiplication/division) without runtime overhead; this further enables SIMD.

- it’s GPU-ready without a single CUDA.jl-related line of code. – This is because the scalar struct design is a [bits type](https://cuda.juliagpu.org/stable/tutorials/custom_structs/).
- MATLAB/Python + C solution could never reach this performance (because they don’t have generated function)

Some materials are written in Chinese, and there’s also a talk about it in the JuliaCN meetup 2022 at [bilibili](https://www.bilibili.com/video/BV1MG4y1J7E2)

> It’s 1000 times faster than MATLAB’s C codes

Don’t ever try to conclude that Julia is 1000 times faster than C. It’s Julia plus the code design for a very specific example that makes this possible.

* * *

I was one of the core maintainers of JuliaImages and I’ve used Julia for over five years. Now I’m working full-time at [TongYuan](https://github.com/Suzhou-Tongyuan). It’s a busy life here, and this post is written quickly without much detailed explanation (sorry… 😢 ). If you had any questions about the source codes, I’ll reply when I get available.

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)
#### Post date: [April 24, 2023, 7:43am UTC](https://discourse.julialang.org/t/why-i-still-recommend-julia-how-300-lines-of-julia-code-being-1000x-faster-than-matlabs-c-mex-codes/97842/2 "2023-04-24T07:43:11Z")

</div>

It might be better if you upload the video to youtube so there’ s auto subtitles.
