travisowens Posted June 3, 2005 Posted June 3, 2005 I read the most interesting benchmark about the speed of string comparisons. It seems there is a HUGE different between the 3 different methods of string comparison. I've also included my summary/notes. I was shocked to find s1.Equals(s2) to be so inefficent in comparison. Source: http://dotnetjunkies.com/WebLog/chris.taylor/archive/2004/05/18/13927.aspx Google Cached Copy: http://216.239.39.104/search?q=cache:http://dotnetjunkies.com/WebLog/chris.taylor/archive/2004/05/18/13927.aspx using if (String.Equals("target", "source")) is 5x faster than using C#'s classic if (myString == "value")and it's 30x faster than VB.Net's if (myString = "value") Please note that myString.Equals("value") is extremely inefficient, almost as slow as VB.Net's = comparison, because it does a null check on myString Of course let's interject a reality check here and 99% of the time you won't get any benefit by choosing one method over another. Only in extreme looping situations will it make a difference. Quote Experience is something you don't get until just after the moment you needed it
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.