String Performance: Checking for a Character

The article compares two methods of checking for the presence of a specific character in a string in C#. Benchmark results reveal that using a character in the search is 3.57 times more efficient than using a string, and Contains() outperforms StringComparison.Ordinal and StringComparison.OrdinalIgnoreCase in terms of speed.

Mastering Globalization

Internationalization and localization are crucial for software projects, involving adapting to various languages, regions, and technical requirements. Delaying consideration until later stages can lead to significant costs and effort. The importance of addressing globalization from the outset is emphasized, along with a recommendation to explore the book "Rock Your Code: Coding Standards for Microsoft .NET" for comprehensive insights.

Optimizing String Performance

These articles delve into the intricacies of string handling in programming, emphasizing the fundamental role strings play in representing text. It explores various aspects such as checking for empty strings efficiently, verifying if an object is a string, string comparison methods, formatting strings, checking for substrings and characters, retrieving and slicing substrings, concatenating strings, optimizing concatenation with StringBuilder and ObjectPool, appending single characters, encoding and decoding strings, and string compression using Brotli, Deflate, GZip, and ZLib formats. Benchmark results are provided throughout, offering insights into performance considerations. Additionally, the chapter highlights recommendations and best practices for string manipulation while referencing my open-source project, Spargine, for streamlined string handling processes.

String Performance: Appending a Character using the StringBuilder

The use of a single character with a StringBuilder from an ObjectPool can improve performance. Benchmark results show similar overall performance, but without an ObjectPool, using a character becomes more significant. It is recommended to use a character in such cases. EditorConfig setup can check for this issue using dotnet_diagnostic.CA1834.severity = warning.

String Performance: Optimizing String Substring Extraction – Slicing vs. AsSpan()

The content presents an alternative approach to obtaining a substring using slicing with ReadOnlySpan and AsSpan() methods, delivering performance improvement of 2.4 times based on benchmark tests. Configuration for detecting this issue in EditorConfig is also provided using dotnet_diagnostic.CA1831.severity = error.

Boosting Performance and Memory Efficiency: Introducing ToDelimitedString() with Source Generators in Spargine

The article introduces a method called ToDelimitedString() in programming, using a StringBuilder and commas to create a delimited string. Benchmark results indicate that this method is 1.23 times more performant and allocates less memory, thanks to the utilization of a source generator in Spargine.

String Performance: Checking for a Character

Developers commonly check for a specific character in a string using methods like "Contains('M')" or "Contains("M")". Benchmark results show that using a character is 3.57 times more efficient than using a string. To check for this issue, the configuration in EditorConfig is set to dotnet_diagnostic.CA1847.severity = error.