Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pmocz/nbody-performance-comparison
Directly compare performance of vectorized and for-loop implementations of the N-body problem in Matlab, Julia, and Python
https://github.com/pmocz/nbody-performance-comparison
Last synced: 3 months ago
JSON representation
Directly compare performance of vectorized and for-loop implementations of the N-body problem in Matlab, Julia, and Python
- Host: GitHub
- URL: https://github.com/pmocz/nbody-performance-comparison
- Owner: pmocz
- License: gpl-3.0
- Created: 2020-09-13T17:25:04.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-13T17:33:38.000Z (about 4 years ago)
- Last Synced: 2024-07-04T02:15:07.020Z (4 months ago)
- Language: Python
- Size: 85.9 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 Univeristy, [@PMocz](https://twitter.com/PMocz)
Run the various versions:
```
matlab nbody_vec.m
julia nbody_vec.jl
python nbody_vec.pymatlab nbody_for.m
julia nbody_for.jl
python nbody_for.pypython nbody_for_numba.py
```![Simulation](./comparison.png)
## Some Takeaways
* Python for loops are horribly SLOW!! Use **numba** to improve performance. Decorate bottleneck functions with:
```python
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.