

Will It Optimize? [2010] - kibwen
http://ridiculousfish.com/blog/posts/will-it-optimize.html

======
NAFV_P
Regarding 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;
      }

------
NAFV_P
Regarding 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.

------
valtron
I got 0/6; glad I read this.

