I recently came across this blog post on using String.Compare instead of the tried and true method of converting one string to lowercase and comparing to a known lower case value. It's important to remember that strings in .NET (as in Java) are immutable so the act of lower casing a string will always make a new string. The memory subsystem for .NET is turned for handling lots of small objects but the fewer objects you create, the fewer that have to be checked and managed by the garbage collection system.
Still I wondered what the time difference would be between the two approaches. So I setup a very simple test where I compared the string "FooBar" to a string variable that contained the value "foobar" one million times. The first test used the approach of …
[Read more]