There's no speed difference in them. The library version does a loop through the string itself. Plus you don't need to cast size_t, since it's usually int.