-
Notifications
You must be signed in to change notification settings - Fork 344
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 #2541 from FirelyTeam/feature/2534-improve-date-pe…
…rformance 2534 Improve performance of Date handling
- Loading branch information
Showing
14 changed files
with
490 additions
and
231 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hl7.Fhir.Model; | ||
using System; | ||
|
||
namespace Firely.Sdk.Benchmarks | ||
{ | ||
public class DateTimeBenchmarks | ||
{ | ||
[GlobalSetup] | ||
public void BenchmarkSetup() | ||
{ | ||
_dateTimeInstance = new FhirDateTime(DATETIME); | ||
_ = _dateTimeInstance.TryToDateTime(out var _); // trigger initial compile of regex | ||
|
||
_dateInstance = new Date(DATE); | ||
_ = _dateInstance.TryToDate(out var _); // trigger initial compile of regex | ||
} | ||
|
||
private const string DATETIME = "2023-07-11T13:00:00"; | ||
private FhirDateTime _dateTimeInstance; | ||
|
||
[Benchmark] | ||
public DateTimeOffset DateTimeToDTO_Uncached() | ||
{ | ||
// Clear the cache each invocation | ||
_dateTimeInstance.Value = DATETIME; | ||
_ = _dateTimeInstance.TryToDateTimeOffset(TimeSpan.Zero, out var result); | ||
_dateTimeInstance.Value = null; | ||
|
||
return result; | ||
} | ||
|
||
[Benchmark] | ||
public DateTimeOffset DateTimeToDTO_Cached() | ||
{ | ||
_ = _dateTimeInstance.TryToDateTimeOffset(TimeSpan.Zero, out var result); | ||
return result; | ||
} | ||
|
||
private const string DATE = "2023-07-11"; | ||
private Date _dateInstance; | ||
|
||
|
||
[Benchmark] | ||
public DateTimeOffset DateToDTO_Uncached() | ||
{ | ||
// Clear the cache each invocation | ||
_dateInstance.Value = DATETIME; | ||
_ = _dateInstance.TryToDateTimeOffset(out var result); | ||
_dateInstance.Value = null; | ||
|
||
return result; | ||
} | ||
|
||
[Benchmark] | ||
public DateTimeOffset DateToDTO_Cached() | ||
{ | ||
_ = _dateInstance.TryToDateTimeOffset(out var result); | ||
return result; | ||
} | ||
} | ||
} |
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.