This article discusses the performance differences using string.Format() and interpolation and stresses the importance of using globalization with any string shown to the user. Updated January 2023.
Category: Defensive Programming
String Performance: The Fastest Way to Get a String’s Length
The article highlights the importance of using efficient methods for checking if a string is empty or null, emphasizing the performance benefits and exception prevention of using `string.IsNullOrEmpty()` and `string.IsNullOrWhiteSpace()` over the traditional `if (emailAddress == "")` approach. Benchmark results reveal that using null and `string.Empty()` is the most performant way to check for an empty string, with other methods showing similar performance levels. Updated January 2024.
Collection Performance: Sort() with CompareTo()
Let’s discuss for() and foreach() under load to establish a baseline. As you can see below, I used the same code in the previous chapter and added Task.Delay() to simulate a CPU load.
dotNetDave Rocks The GLUGnet User Group
The dotNetDave For Those About To Code: Worldwide Tour will be at the GLUGnet User Group in Okemos, MI on August 19th at 6 PM EDT. I hope you will join me at this meeting. This meeting will be virtual, but I wish it was in person. My session will be followed by a Q&A where you can ask me anything!
dotNetDave Rocks The Tech Valley .NET User Group
The dotNetDave For Those About To Code: Worldwide Tour will be at the Tech Valley .NET User Group (TVUG) in Latham, NY on August 10, 2021.
Serializing Objects: JSON Serialization
The article explores the significance of object serialization into JSON format, comparing Newtonsoft.Json and JsonSerializer in .NET.
Collection Performance Under Load: for() and foreach()
Let’s discuss for() and foreach() under load to establish a baseline. As you can see below, I used the same code in the previous chapter and added Task.Delay() to simulate a CPU load.
String Performance: String Comparison
The article discusses the importance of choosing the right string comparison method in coding, emphasizing the use of ToUpperInvariant() for accurate globalized comparisons, and presents benchmark results showing its performance advantage. It also briefly mentions the comparison between the == operator and Equals() for checking string equality. Updated January 2024.
Collection Performance: Looping Over a Collection
There are four main ways to loop through a collection by using for(), foreach(), do() and while(). Let’s see which one of these methods are the most performant along with using the generic ForEach() method. Updated September 2023.
Reference Type & Structure Performance: Best Practices
General best practices for types. Updated January 2023.

You must be logged in to post a comment.