Here are some test results from major browsers (a few months ago). He concludes that toLowerCase() is faster, but there is no understanding of why this is provided.
EDIT:
I went and looked at the source code of WebKit JavaScript just out of curiosity. The prototype methods .toUpperCase() and .toLowerCase() identical, with the exception of some calls to .toASCIIUpper() , .toASCIILower() and Unicode::toUpper() and Unicode::toLower() . Further, checking the first two methods, I saw that the .toLowerCase() function is a little less complicated than the .toUpperCase() function.
.toASCIILower() performs some simple bit offset logic:
char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
.toASCIIUpper() bit more complicated:
char toASCIIUpper(char c) { return static_cast<char>(c & ~((c >= 'a' && c <= 'z') << 5)); }
Static addition and incremental bitwise negation (~) in the .toASCIIUpper() function, repeated over a million iterations, could explain its lower performance.
Now this is all speculative; I did not conduct any real tests, and I did not try to fully understand these methods, but maybe someone else can develop.
Cᴏʀʏ
source share