Skip to content

albertherd/csharpmopt2-in

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Exploring C# Micro Optimizations Part 2 – In Arguments

Follow the accompanying blog post here - https://albertherd.com/2019/06/20/c-micro-optimizations-part-1-ref-arguments/

Exploring overcoming the mutability issue presented using the ref keyword by using in parameter modifier with readonly structs

When accessing 2 properties in a struct, the performance difference between a ref method and an in method without having a read-only struct, performance is around 10 times slower.

MethodlimitMeanErrorStdDev
BenchmarkIncrementByRef10000000023.83 ms0.0272 ms0.0241 ms
BenchmarkIncrementByIn100000000238.21 ms0.3108 ms0.2755 ms

When switching the struct to read-only, the performance hit is not evident anymore

MethodlimitMeanErrorStdDev
BenchmarkIncrementByRef10000000023.93 ms0.1226 ms0.1147 ms
BenchmarkIncrementByIn10000000024.06 ms0.2183 ms0.2042 ms

Releases

No releases published

Packages

No packages published

Languages