How to calculate the length of a string in C efficiently (in time)?
Right now I'm doing:
int calculate_length(char *string) {
int length = 0;
while (string[length] != '\0') {
length++;
}
return length;
}
But it's very slow compared to strlen() for example, is there any other way to do it?
Thanks.
EDIT: I'm working in a freestanding environment, I'm not allowed to use any external lib including "string.h".