forked from FirelyTeam/firely-net-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christian Donn Relacion Sarmago (Synapxe)
committed
May 30, 2024
1 parent
776e52d
commit 5e86101
Showing
18 changed files
with
724 additions
and
83 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
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 |
---|---|---|
@@ -1,66 +1,173 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hl7.Fhir.Introspection; | ||
using Hl7.Fhir.Model; | ||
using Hl7.Fhir.Utility; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Firely.Sdk.Benchmarks | ||
namespace Firely.Sdk.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class ModelInspectorBenchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class ModelInspectorBenchmarks | ||
[GlobalSetup] | ||
public void BenchmarkSetup() | ||
{ | ||
[GlobalSetup] | ||
public void BenchmarkSetup() | ||
{ | ||
// PropertyInfoExtensions.NoCodeGenSupport = true; | ||
} | ||
// PropertyInfoExtensions.NoCodeGenSupport = true; | ||
|
||
var inspector = ScanAssemblies(); | ||
Console.WriteLine($"ScanAssemblies: Types: {inspector.ClassMappings.Count}, Enums: {inspector.EnumMappings.Count()}"); | ||
|
||
internal Type[] PopularResources = new Type[] | ||
{ | ||
typeof(Observation), typeof(Patient), typeof(Organization), | ||
typeof(Procedure), typeof(StructureDefinition), typeof(MedicationRequest), | ||
typeof(ValueSet), typeof(Questionnaire), typeof(Appointment), | ||
typeof(OperationOutcome) | ||
}; | ||
|
||
[Benchmark] | ||
public void ScanAssemblies() | ||
{ | ||
// Make sure we work uncached initially on each run | ||
//ModelInspector.Clear(); | ||
//ClassMapping.Clear(); | ||
inspector = ImportTypeAllResources(); | ||
Console.WriteLine($"ImportTypeAllResources: Types: {inspector.ClassMappings.Count}, Enums: {inspector.EnumMappings.Count()}"); | ||
|
||
inspector = NewWithSourceGenMappings(); | ||
Console.WriteLine($"NewWithSourceGenMappings: Types: {inspector.ClassMappings.Count}, Enums: {inspector.EnumMappings.Count()}"); | ||
|
||
inspector = NewWithTypesAllResources(); | ||
Console.WriteLine($"NewWithTypesAllResources: Types: {inspector.ClassMappings.Count}, Enums: {inspector.EnumMappings.Count()}"); | ||
|
||
inspector = ImportType4Resources(); | ||
Console.WriteLine($"ImportType4Resources: Types: {inspector.ClassMappings.Count}, Enums: {inspector.EnumMappings.Count()}"); | ||
|
||
inspector = NewWithTypes4Resources(); | ||
Console.WriteLine($"NewWithTypes4Resources: Types: {inspector.ClassMappings.Count}, Enums: {inspector.EnumMappings.Count()}"); | ||
} | ||
|
||
internal static readonly Type[] PopularResources = new Type[] | ||
{ | ||
typeof(Observation), typeof(Patient), typeof(Organization), | ||
typeof(Procedure), typeof(StructureDefinition), typeof(MedicationRequest), | ||
typeof(ValueSet), typeof(Questionnaire), typeof(Appointment), | ||
typeof(OperationOutcome) | ||
}; | ||
|
||
|
||
internal static readonly Type[] TestResources = | ||
[ | ||
typeof(CapabilityStatement), typeof(Appointment), typeof(OperationDefinition), | ||
]; | ||
|
||
_ = ModelInspector.ForAssembly(typeof(ModelInfo).Assembly); | ||
//[IterationSetup] | ||
//[IterationCleanup] | ||
public void ResetCache() | ||
{ | ||
// Make sure we work uncached initially on each run | ||
ModelInspector.Clear(); | ||
ClassMapping.Clear(); | ||
EnumMapping.Clear(); | ||
} | ||
|
||
[Benchmark] | ||
public ModelInspector ScanAssemblies() | ||
{ | ||
ResetCache(); | ||
return ModelInspector.ForAssembly(typeof(ModelInfo).Assembly); | ||
} | ||
|
||
[Benchmark] | ||
public ModelInspector ImportTypeAllResources() | ||
{ | ||
ResetCache(); | ||
var inspector = new ModelInspector(Hl7.Fhir.Specification.FhirRelease.R5); | ||
foreach (var t in ModelInfo.GenerateAllFhirTypes()) | ||
{ | ||
inspector.ImportType(t); | ||
} | ||
|
||
[Benchmark] | ||
public void GetPropertiesPopular() | ||
return inspector; | ||
} | ||
|
||
[Benchmark] | ||
public ModelInspector ImportType4Resources() | ||
{ | ||
ResetCache(); | ||
var inspector = new ModelInspector(Hl7.Fhir.Specification.FhirRelease.R5); //ModelInspector.ForAssembly(typeof(ModelInfo).Assembly); | ||
foreach (var t in TestResources) | ||
{ | ||
// Make sure we work uncached initially on each run | ||
//ModelInspector.Clear(); | ||
//ClassMapping.Clear(); | ||
|
||
var inspector = ModelInspector.ForAssembly(typeof(ModelInfo).Assembly); | ||
foreach (var t in PopularResources) | ||
{ | ||
var mapping = inspector.FindClassMapping(t); | ||
_ = mapping.PropertyMappings; | ||
} | ||
inspector.ImportType(t); | ||
} | ||
|
||
//[Benchmark] | ||
//public void GetPropertiesAll() | ||
//{ | ||
// // Make sure we work uncached initially on each run | ||
// ModelInspector.Clear(); | ||
// ClassMapping.Clear(); | ||
return inspector; | ||
} | ||
|
||
// var inspector = ModelInspector.ForAssembly(typeof(ModelInfo).Assembly); | ||
// foreach (var m in inspector.ClassMappings) | ||
// { | ||
// _ = m.PropertyMappings; | ||
// } | ||
//} | ||
[Benchmark] | ||
public ModelInspector NewWithSourceGenMappings() | ||
{ | ||
FhirReleaseParser.Parse(ModelInfo.Version); | ||
ResetCache(); | ||
return new ModelInspector(ModelInfo.GenerateAllClassMappings(), ModelInfo.GenerateAllEnumMappings()) { FhirRelease = Hl7.Fhir.Specification.FhirRelease.R5 }; | ||
} | ||
|
||
[Benchmark] | ||
public ModelInspector NewWithTypesAllResources() | ||
{ | ||
FhirReleaseParser.Parse(ModelInfo.Version); | ||
ResetCache(); | ||
return ModelInspector.ForTypes(ModelInfo.Version, ModelInfo.GenerateAllFhirTypes()); | ||
} | ||
|
||
[Benchmark] | ||
public ModelInspector NewWithTypes4Resources() | ||
{ | ||
ResetCache(); | ||
var inspector = ModelInspector.ForTypes(ModelInfo.Version, [ | ||
typeof(CapabilityStatement), | ||
typeof(CapabilityStatement.ConditionalDeleteStatus), | ||
typeof(CapabilityStatement.ConditionalReadStatus), | ||
typeof(CapabilityStatement.DocumentMode), | ||
typeof(CapabilityStatement.EventCapabilityMode), | ||
typeof(CapabilityStatement.ReferenceHandlingPolicy), | ||
typeof(CapabilityStatement.ResourceVersionPolicy), | ||
typeof(CapabilityStatement.RestfulCapabilityMode), | ||
typeof(CapabilityStatement.SystemRestfulInteraction), | ||
typeof(CapabilityStatement.TypeRestfulInteraction), | ||
typeof(CapabilityStatement.DocumentComponent), | ||
typeof(CapabilityStatement.EndpointComponent), | ||
typeof(CapabilityStatement.ImplementationComponent), | ||
typeof(CapabilityStatement.MessagingComponent), | ||
typeof(CapabilityStatement.OperationComponent), | ||
typeof(CapabilityStatement.ResourceComponent), | ||
typeof(CapabilityStatement.ResourceInteractionComponent), | ||
typeof(CapabilityStatement.RestComponent), | ||
typeof(CapabilityStatement.SearchParamComponent), | ||
typeof(CapabilityStatement.SecurityComponent), | ||
typeof(CapabilityStatement.SoftwareComponent), | ||
typeof(CapabilityStatement.SupportedMessageComponent), | ||
typeof(CapabilityStatement.SystemInteractionComponent), | ||
typeof(Appointment), | ||
typeof(Appointment.AppointmentStatus), | ||
typeof(Appointment.IANATimezones), | ||
typeof(Appointment.ParticipationStatus), | ||
typeof(Appointment.WeekOfMonth), | ||
typeof(Appointment.MonthlyTemplateComponent), | ||
typeof(Appointment.ParticipantComponent), | ||
typeof(Appointment.RecurrenceTemplateComponent), | ||
typeof(Appointment.WeeklyTemplateComponent), | ||
typeof(Appointment.YearlyTemplateComponent), | ||
typeof(OperationDefinition), | ||
typeof(OperationDefinition.BindingComponent), | ||
typeof(OperationDefinition.OperationKind), | ||
typeof(OperationDefinition.OperationParameterScope), | ||
typeof(OperationDefinition.OverloadComponent), | ||
typeof(OperationDefinition.ParameterComponent), | ||
typeof(OperationDefinition.ReferencedFromComponent), | ||
]); | ||
return inspector; | ||
} | ||
|
||
//[Benchmark] | ||
//public void GetPropertiesAll() | ||
//{ | ||
// // Make sure we work uncached initially on each run | ||
// ModelInspector.Clear(); | ||
// ClassMapping.Clear(); | ||
|
||
// var inspector = ModelInspector.ForAssembly(typeof(ModelInfo).Assembly); | ||
// foreach (var m in inspector.ClassMappings) | ||
// { | ||
// _ = m.PropertyMappings; | ||
// } | ||
//} | ||
|
||
} |
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
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
Oops, something went wrong.