For example, in <ctype.h> there are functions like isalpha().
I want to know if writing an isalpha function on my own is faster than calling isalpha?
Thanks for all your instant replies! just want to make clearer to my question:
so even for the isalpha function? because you can simply pass a character and check if the character is between ‘a’ and ‘z’ || ‘A’ and ‘Z’?
another question: when you include a std library like ctype.h and just call one function like isalpha, will the file(I mean all lines of code) be loaded? My concern is that the big-size will make program slower
Unless you have specific reason to do so (e.g., you have a specific requirement not to use the standard library or you’ve profiled a very specific use case where you can write a function that performs better), you should always prefer to use a standard library function where one exists rather than writing your own function.
The standard library functions are heavily optimized and very well tested. In addition, the standard library that ships with your compiler can take advantage of compiler intrinsics and other low-level details that you can’t portably use in your own code.