Most code analysis tools advocate for static methods due to perceived performance benefits. However, benchmarks indicate that non-static methods often outperform static ones despite avoiding instance dispatch. It's advisable to choose function types based on team coding standards. EditorConfig settings can help manage these preferences effectively.
Category: Defensive Programming
Code It Any Way You Want: Performance Considerations for Sealed and Internal Classes
This article explores the historical belief that sealed and internal classes in .NET might offer performance advantages, but suggests that in modern .NET runtimes, compiler optimizations, and hardware advancements, the difference in performance is likely negligible, emphasizing that design considerations should drive decisions regarding class sealing or internalization rather than performance concerns.
General Performance: Type Conversion
In .NET programming, type conversion can be done using explicit casting, the "as" keyword, or the declaration pattern for improved safety and readability. The declaration pattern efficiently checks and casts types in one step, outperforming traditional methods.
Reference Type & Structure Performance: Constant vs. Read-only Property
This content discusses the performance of using a constant vs. a read-only property.
Code It Any Way You Want: Constants vs. Properties
The post discusses the importance of using constants for static numerical or string values in code, highlighting benefits such as clarity of intent. It provides an example of a read-only property for π and notes that .NET 10 benchmarks show similar performance for both methods. EditorConfig settings for identifying issues are also mentioned.
General Performance Tip: Choosing Between Conditional Statements – If, Switch, and Switch Expression Performance in C#
The content discusses coding preferences between conditional if statements, switch statements, and switch expressions in C#.
Code It Any Way You Want: Performance Impact of Sealing Attributes
The excerpt discusses the recommendation to seal classes in .NET for design clarity and adherence to OOP principles, while noting that benchmark tests reveal non-sealed classes perform slightly better. Despite this, the author maintains sealing classes not meant for inheritance is essential for robust class design. An EditorConfig setup for checking this is also mentioned.
Collection Performance: Is LINQ Always the Most Performant Choice?
The article explores the performance implications of using LINQ for collection queries, finding that a conventional foreach() loop outperforms LINQ by 1.75 times in identifying items matching a given query. The conclusion suggests benchmarking to determine the optimal approach based on the nature of the query and elements being sought.
Code It Any Way You Want: Comparison of Passing Parameters in Methods
This article explores different methods of passing parameters into methods, including conventional, in operator, and ref readonly approaches, comparing their performance. Despite differences in syntax, benchmark results demonstrate similar performance among these methods.
Code It Any Way You Want: Optimal Parameter Passing – Array vs. Params Keyword
The article explores the performance differences between passing parameters as arrays or using the params keyword in C#. Despite similarities in speed, the author recommends using the params keyword for its ease of use during function calls.

You must be logged in to post a comment.