cstringtime-complexitystrncmp

Complexity of strncmp in string.h


I would like to know the time complexity of int strncmp(const char *__s1, const char *__s2, size_t __n) which is in the C library(string.h).

I have to study the complexity of my whole program which is calling strncmp thousands of time, I can't ignore this complexity.
Where can I find documentation about the complexity of c library function ?


Solution

  • The standard imposes no requirements on the complexity. That is entirely up to the implementation. But there's absolutely no reason to expect it to be anything else than O(__n)

    But if you want to be sure, you have to study the particular implementation you're using.