2 ms·
Will It Optimize? [2010]
- valtron 13y agoI got 0/6; glad I read this.
- NAFV_P 13y agoRegarding number 2: Loop-invariant strlen(): I would write the loop as the optimised version first hand, especially if there were nested loops. No. 5 caught me out, but I'm not surprised.
- NAFV_P 13y agoRegarding number 2 (again): unsigned sum(const unsigned char *s) { unsigned result = 0; size_t length = strlen(s); for (size_t i=0; i < length; i++) { result += s[i]; } return result; } But it could be written as: unsigned sum(const unsigned char *s) { unsigned result = 0; size_t length = strlen(s); for (size_t i=0; i < length; ++i) // prefix increment should be quicker. result += s[i]; return result; }