Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.73 KB

README.md

File metadata and controls

35 lines (27 loc) · 1.73 KB

.NET

EnumConverterDemo

Experimenting enum type converters

In this demo, i m experimenting ways of conversion from enums (decorated with EnumMember) to strings

The enum converter should support the following cases :

📌 From string enum value To enum value

📌 From string integer enum value To enum value

📌 From string enum member value value To enum value

The built-in implementation EnumConverter provided by microsoft don't support the last case about EnumMember

In order to support all the cases, i m testing and benchmarking two implementations :

1️⃣ StringEnumConverter

2️⃣ CachedStringEnumConverter

|                         Method |        Mean |       Error |      StdDev |      Median |         Min |         Max | Rank |  Gen 0 | Allocated |
|------------------------------- |------------:|------------:|------------:|------------:|------------:|------------:|-----:|-------:|----------:|
| UsingCachedStringEnumConverter |    850.0 ns |    32.96 ns |    95.62 ns |    837.3 ns |    683.3 ns |  1,102.1 ns |    1 | 0.0229 |      96 B |
|       UsingStringEnumConverter | 27,620.3 ns | 1,816.07 ns | 5,151.88 ns | 25,850.7 ns | 21,417.7 ns | 43,805.8 ns |    2 | 1.0986 |   4,818 B |

Tools : vs22, net 6.0, xunit, fluent-assertions, benchmark-dotnet