paulchernoch / hilbert

Hilbert Transformation and inverse for Rust
MIT License
72 stars 8 forks source link

Optimisation of dot product calculation #1

Closed DoubleHyphen closed 3 years ago

DoubleHyphen commented 4 years ago

Manual loop unrolling does not, in fact, speed things up. In fact, after I ran a few benchmarks... https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=84d18b38b9ed805c87d16992a96c5ade ...it appears to slow things down significantly. The reason being: For every manual vector access, the program needs to check if it is in bounds or not. If you just tell the compiler "Just take those two vectors, multiply them element-by-element, and then sum everything up" then it knows exactly what to do in order to optimise.

Takeaway lesson: Rust is not C#.