Fastest? Perhaps. Wrongest? Certainly!

by Michael S. Kaplan, published on 2009/10/22 07:01 -04:00, original URI:

The question was deceptively simple:


I used all three and I find ToLower() to be fastest .But the Msdn article says that ToLowerInvariant should be faster. .
Which one is better with respect to performance.

Results are ,

173ms ToLower
260ms ToLowerInvariant
265ms ToLowerCultureInfoInvariant

The results seem okay to me, it is the link that is off a bit....

It is a matter of where/how you aim expectations.

You see, starting in .Net 2.0 (and subsequent versions), "invariant" casing actually means "use the operating system casing results" and also "don't do those weird linguistic results".

Thus just using ToLower() will cause you to miss hundreds of characters being mapped, and it will map some characters likely best left alone.

Performance is one reasonable axis to use for the judging of results, but correctness is, too, right?

The ad campaign "ToLower may be wrongest, but at least it can be fastest!" is unlikely to be as effective as that 5-year old using Windows 7. :-)

c on 6 Jan 2010 6:39 AM:

No examples? :-|

What would ToLower() miss? And which characters are likely best left alone?

Aren't some languages more affected than others?

Michael S. Kaplan on 6 Jan 2010 9:51 AM:

I have spoken, in many other blogs, about how the casing table was updated in Vista to add hundreds of case pairs that are not in the older tables .Net uses....

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day