python3+numba n-body contribution
Python3+Numba N-Body Implementation
Numba (pip install numba) uses the LLVM compiler as a JIT solution for python3. I based this off the nice Rust version from Ilia Schelokov (rust-8).
Source
i7 Laptop Benchmarks
| n-body | |
|---|---|
| rust-8 | 2.3 s |
| py3 | 5722 s |
| py3+numba | 175.6 s |
| py3+numba+fm | 169.9 s |
It run evens faster if you add cache=True to the decorator, but it only helps upon running the program a second time. fm indicates fastmath=True.
This implementation is 74x slower than Rust, but 35x faster than normal python3.
Run
$ python3 nbody.py 50000000
-0.169075164
-0.169059907