Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Ref
 
 
 
 
 
 
 
 

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.

About

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

Topics

Resources

Releases

No releases published

Packages

No packages published

Languages