for (s = i = 0; i < NUMBER; ++i) {
s += 1;
}
I'm surprised gcc can't figure out that this is NUMBER*(NUMBER-1) and eliminate the loop entirely. for (s = i = 0; i < NUMBER; ++i) {
s += 1;
}
I'm surprised gcc can't figure out that this is NUMBER*(NUMBER-1) and eliminate the loop entirely.Huh? Do you mean NUMBER instead? If it were s += i then that would be NUMBER * (NUMBER-1) / 2.
But with -O3, for NUMBER > 51, is uses some other odd loop. [1]
Seems to be O(n) no matter what though.
[0]: https://godbolt.org/z/czcaYf [1]: https://godbolt.org/z/sP194Y