项目作者: albertherd

项目描述 :
C# Micro Optimizations Part 2 – In Arguments
高级语言: C#
项目地址: git://github.com/albertherd/csharpmopt2-in.git
创建时间: 2019-06-24T22:15:35Z
项目社区:https://github.com/albertherd/csharpmopt2-in

开源协议:

下载


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