Based on strings that tend to have lowercase entries, ToLower should theoretically be faster (many comparisons, but several assignments).
In C or when using individually accessible elements of each string (for example, C strings or the STL string type in C ++), this is actually a byte comparison, so the UPPER comparison is no different from lower .
If you were sneaky and loaded your lines into long arrays instead, you would get a very fast comparison over the entire line, because it could compare 4 bytes at a time. However, loading times may make it impractical.
Why do you need to know which is faster? If you don’t perform the metric load of comparisons, one that performs a couple of loops faster is not related to the overall execution speed and sounds like a premature optimization :)
warren Oct. 24 '08 at 17:51 2008-10-24 17:51
source share