Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
maple3142
· 5y ago · 0 comments
Summation from 1 to n:
https://godbolt.org/z/673hTr
clang seems to optimize it to (n-1)(n-2)/2+2n-1, which is O(1).
Comments
[–]
mehrdadn
5y ago
Even more trivial: sum from 1 to n, then never use the result. It should get optimized out entirely!