Skip to content
Exploring micro optimizations in c# Part 1 - using ref with structs
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Ref
.gitignore
README.md
Ref.sln

README.md

Exploring micro optimizations in c# Part 1 - using ref with structs

Exploring micro optimizations in c# Part 1 - using ref with structs

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

Exploring the performance differences when passing values by ref or by value with structs (value types). The bigger the struct is, the bigger the performance uplift.

Performance differences in structs

When comparing a 16-byte struct, the performance differences when doing work by ref instead of by value is illustrated in the following benchmark. Work by ref exhibit around 72% lift in performance.

MethodlimitMeanErrorStdDev
BenchmarkIncrementByRef10000001.663 ms0.0139 ms0.0130 ms
BenchmarkIncrementByVal10000002.872 ms0.0155 ms0.0145 ms

Full description along with IL Analysis can be found in the blog post linked above.

You can’t perform that action at this time.