Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToTypedElementOnSourceNode: caching children and value #1882

Merged
merged 8 commits into from
Oct 12, 2021
2 changes: 1 addition & 1 deletion common
6 changes: 4 additions & 2 deletions src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Firely.Sdk.Benchmarks</AssemblyName>
<AssemblyName>Firely.Sdk.Benchmarks</AssemblyName>
<RootNamespace>Firely.Sdk.Benchmarks</RootNamespace>
</PropertyGroup>

Expand All @@ -12,7 +12,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\common\src\Hl7.Fhir.ElementModel\Hl7.Fhir.ElementModel.csproj" />
<ProjectReference Include="..\Hl7.Fhir.Core\Hl7.Fhir.Core.csproj" />
<ProjectReference Include="..\Hl7.Fhir.Specification\Hl7.Fhir.Specification.csproj" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions src/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ namespace Firely.Sdk.Benchmarks
{
public class Program
{
public static void Main(string[] args)
{
_ = BenchmarkRunner.Run<ModelInspectorBenchmarks>();
}
static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
35 changes: 35 additions & 0 deletions src/Benchmarks/ToTypedElementBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using BenchmarkDotNet.Attributes;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification;
using Hl7.Fhir.Specification.Source;

namespace Firely.Sdk.Benchmarks
{
[MemoryDiagnoser]
public class ToTypedElementBenchmarks
{
private readonly IStructureDefinitionSummaryProvider _provider;
private readonly string _json = "{ \"resourceType\": \"Patient\", \"active\": true, \"contact\": [{\"organization\": {\"reference\": \"Organization/1\", \"display\": \"Walt Disney Corporation\" }, \"period\": { \"start\": \"0001-01-01\", \"end\": \"2018\" } } ],}";

public ToTypedElementBenchmarks()
{
_provider = new StructureDefinitionSummaryProvider(ZipSource.CreateValidationSource());
}


[Benchmark]
public void ToTypedElementOnSourceNode()
{
for (int i = 0; i < 10; i++)
{
var patient = FhirJsonNode.Parse(_json).ToTypedElement(_provider);

patient.VisitAll();

// second time should be faster, when the children and values are cached
patient.VisitAll();
}
}
}
}