2 ms·
I would be shocked if those two programs performed the same. C and Rust are using the same compiler backend, better aliasing information probably isn't going to
by creato 6y ago
I would be shocked if those two programs performed the same. C and Rust are using the same compiler backend, better aliasing information probably isn't going to make that big of a difference.
Are you sure the rust performance data isn't for one of the other implementations that use the same crufty tricks as the C version?
e.g.: https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-rust-5.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/..., https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-rust-7.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- pjscott 6y agoIt's pretty startling, but yes, that non-crufty version is "Rust #8" that tops the n-body performance lists: https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/nbody.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... It looks like the autovectorizer did a really good job on this one.
- creato 6y agoIt also looks like this version is using an algorithm that none of the others use: it precomputes the distance pairs for all bodies. Some of the others precompute the vectors between the pairs, but that's not the expensive part of computing the distance. As an aside: this made me notice this n-body simulation only has 5 bodies! This is a pretty strange case that makes these O(n^2) optimizations practical. The n-body simulations I've been familiar with in the past had thousands of bodies, where this approach probably isn't a good idea.