Skip to content

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

Notifications You must be signed in to change notification settings

albertherd/csharpmopt1-ref

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages