-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2596 from almostchristian/develop
Improve performance of EnumUtility generic methods
- Loading branch information
Showing
3 changed files
with
206 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hl7.Fhir.Model; | ||
using Hl7.Fhir.Utility; | ||
using System; | ||
|
||
namespace Firely.Sdk.Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class EnumUtilityBenchmarks | ||
{ | ||
private static readonly SearchParamType StringSearchParam = SearchParamType.String; | ||
private static readonly Enum StringSearchParamEnum = StringSearchParam; | ||
|
||
[Benchmark] | ||
public string EnumToString() | ||
=> SearchParamType.String.ToString(); | ||
|
||
[Benchmark] | ||
public string EnumGetName() | ||
=> Enum.GetName(StringSearchParam); | ||
|
||
[Benchmark] | ||
public string EnumUtilityGetLiteral() | ||
=> EnumUtility.GetLiteral(StringSearchParam); | ||
|
||
[Benchmark] | ||
public string EnumUtilityGetLiteralNonGeneric() | ||
=> EnumUtility.GetLiteral(StringSearchParamEnum); | ||
|
||
[Benchmark] | ||
public SearchParamType EnumParse() | ||
=> Enum.Parse<SearchParamType>("String"); | ||
|
||
[Benchmark] | ||
public SearchParamType EnumParseIgnoreCase() | ||
=> Enum.Parse<SearchParamType>("string", true); | ||
|
||
[Benchmark] | ||
public SearchParamType EnumUtilityParseLiteral() | ||
=> EnumUtility.ParseLiteral<SearchParamType>("string").Value; | ||
|
||
[Benchmark] | ||
public Enum EnumUtilityParseLiteralNonGeneric() | ||
=> EnumUtility.ParseLiteral("string", typeof(SearchParamType)); | ||
|
||
[Benchmark] | ||
public SearchParamType EnumUtilityParseLiteralIgnoreCase() | ||
=> EnumUtility.ParseLiteral<SearchParamType>("string", true).Value; | ||
|
||
[Benchmark] | ||
public Enum EnumUtilityParseLiteralIgnoreCaseNonGeneric() | ||
=> EnumUtility.ParseLiteral("string", typeof(SearchParamType), true); | ||
|
||
[Benchmark] | ||
public string? EnumUtilityGetSystem() | ||
=> EnumUtility.GetSystem(StringSearchParam); | ||
|
||
[Benchmark] | ||
public string EnumUtilityGetSystemNonGeneric() | ||
=> EnumUtility.GetSystem(StringSearchParamEnum); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters