String equality
akutz has one of the most detailed post on string interning and equality comparison performance metrics I have ever seen. Head over to the post here
I loved his conclusion which is the crux of the whole story.
"In conclusion, the String class’s static Equals method is the most efficient way to compare two string literals and the String class’s instance Equals method is the most efficient way to compare two runtime strings. The kicker is that there must be 10^5 (100,000) string comparisons taking place before one method starts becoming more efficient than the next. Until then, use whichever method floats your boat. "
Comments
- Anonymous
July 22, 2008
Thanks for providing some great posts over the years. However, I absolutely do not agree with akutz's initial conclusions as he has made at least one very basic micro-benchmarking boo-boo - using DateTime.Now (rather than a StopWatch) for providing his timings. Please see my comments on his post. Thanks, Tim.