Simulation

Matlab, Python and Julia: Scientific Computing Benchmark

AerodynamicsCFD & LBM

A two-kernel benchmark comparing Matlab, Python, Julia, Fortran and C on a memory-bound LBM fluid simulation and a compute-bound N-body galaxy collision, finding Julia runs 4–5 times faster than Matlab or Python on compute-heavy kernels.

Links & Resources

Motivation

Benchmarking programming languages for scientific computing is harder than it looks. Results are problem-dependent — memory-bound and compute-bound problems respond very differently to language-level optimizations. Literal translations between languages are rarely fair comparisons, and highly optimized benchmarks measure programming expertise rather than language speed. The choice of two representative physics simulations was therefore deliberate.

The Two Kernels

The first kernel is Lattice Boltzmann Method fluid flow past a cylinder. LBM involves large structured arrays with simple per-element operations and frequent memory reads. It is largely memory-bound, representative of many lower-order PDE discretizations.

The second kernel is an all-pairs N-body simulation of two colliding galaxies. Every body interacts with every other body at each time step, producing a compute-to-memory ratio that is high and growing with problem size. This pattern is representative of lumped-parameter models with expensive right-hand sides — for example, multibody systems with nonlinear tyre force evaluations.

Results

For the memory-bound LBM case, the three high-level languages perform similarly regardless of optimization level. For the compute-bound N-body case, Julia runs approximately 4 to 5 times faster than both Matlab and Python after optimization. Fortran and C clearly outperform all three high-level languages on both benchmarks, as expected. Julia's advantage in the N-body case over Fortran and C was somewhat narrower than the gap to Matlab and Python, with the caveat that a more experienced low-level programmer might have closed it further.

The addendum benchmark extending to Fortran and C is included in the repository with all source code.

Practical Takeaway

For many real engineering and science simulations, language choice alone does not produce orders-of-magnitude differences in runtime. Algorithm choice, hardware configuration, memory access patterns and vectorization typically dominate. For teams working in Matlab or Python on compute-heavy kernels, Julia merits evaluation. For memory-bound codes, the case is weaker.

The benchmark scripts for all five languages are publicly available on GitHub for independent verification and extension.