You joke but in Rust all of versions 1 to 4 would probably have compiled to the same machine code because LLVM would use Loop Invariant Code Motion and Induction Variable Analysis to perform the same optimisations that are being done by hand here. (Same would be true of most modern C/C++ compilers)
lifthrasiir|2 years ago
asQuirreL|2 years ago
https://godbolt.org/z/Pa6cqd1fb
But the funny thing is, I tried it on my machine, and guess what, the "unoptimised" version is consistently between 4 and 5 times faster than the hand-optimised variants:
https://gist.github.com/amnn/4be5c05975c250d0ea88b62c03f1719...
So that's fun.