Skip to content

Directly compare performance of vectorized and for-loop implementations of the N-body problem in Matlab, Julia, and Python

License

Notifications You must be signed in to change notification settings

pmocz/nbody-performance-comparison

Repository files navigation

nbody-performance-comparison

Directly compare performance of vectorized and for-loop implementations of the N-body problem in Matlab, Julia, and Python

Philip Mocz (2020) Princeton University, @PMocz

Run the various versions:

matlab nbody_vec.m
julia nbody_vec.jl
python nbody_vec.py

matlab nbody_for.m
julia nbody_for.jl
python nbody_for.py

python nbody_for_numba.py

Simulation

Some Takeaways

  • Python for loops are horribly SLOW!! Use numba to improve performance. Decorate bottleneck functions with:
from numba import jit

@jit(nopython=True)
def myFunction( myInput ):
  • Vectorized codes are FAST in all languages, and easier to read. The downside is that they require significantly more memory.

About

Directly compare performance of vectorized and for-loop implementations of the N-body problem in Matlab, Julia, and Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published