I have 2 different versions of strlen which should do the same thing, but I'm not sure which one would be faster, more readable or more energy efficient.
//version 1
size_t strlen(const char *str) {
size_t retval;
for(retval = 0; *str != '\0'; str++) retval++;
return retval;
}
//version2
size_t strlen(const char *str) {
const char *s;
for (s = str; *s; ++s);
return(s - str);
}
Or would they just translate to the same assembly code?