Skip to content

Commit

Permalink
Add benchmarks for DateOnly, TimeOnly and DateTimeOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Jan 11, 2025
1 parent e522d7b commit 8fb0a62
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#if NET8_0_OR_GREATER
using BenchmarkDotNet.Attributes;

namespace aweXpect.Chronology.Benchmarks;

public partial class HappyCaseBenchmarks
{
[Benchmark]
public DateOnly DateOnly_aweXpect()
=> _day.July(_year);

[Benchmark]
public DateOnly DateOnly_DotNet()
=> new(_year, _month, _day);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ namespace aweXpect.Chronology.Benchmarks;

public partial class HappyCaseBenchmarks
{
private readonly int _day = 5;
private readonly int _hour = 14;
private readonly int _minute = 2;
private readonly int _month = 7;
private readonly int _second = 16;
private readonly int _year = 1964;

[Benchmark]
public DateTime DateTime_aweXpect()
=> _day.July(_year).At(_hour, _minute, _second);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using BenchmarkDotNet.Attributes;

namespace aweXpect.Chronology.Benchmarks;

public partial class HappyCaseBenchmarks
{
[Benchmark]
public DateTimeOffset DateTimeOffset_aweXpect()
=> _day.July(_year).At(_hour, _minute, _second).WithOffset(2.Hours());

[Benchmark]
public DateTimeOffset DateTimeOffset_DotNet()
=> new(_year, _month, _day, _hour, _minute, _second, TimeSpan.FromHours(2));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#if NET8_0_OR_GREATER
using BenchmarkDotNet.Attributes;

namespace aweXpect.Chronology.Benchmarks;

public partial class HappyCaseBenchmarks
{
[Benchmark]
public TimeOnly TimeOnly_aweXpect()
=> _hour.Hours(_minute.Minutes(_second.Seconds()));

[Benchmark]
public TimeOnly TimeOnly_DotNet()
=> TimeOnly.FromTimeSpan(new TimeSpan(_hour, _minute, _second));
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ namespace aweXpect.Chronology.Benchmarks;

public partial class HappyCaseBenchmarks
{
private readonly int _milliseconds = 140;

[Benchmark]
public TimeSpan TimeSpan_aweXpect()
=> _milliseconds.Milliseconds();
=> _second.Seconds();

[Benchmark]
public TimeSpan TimeSpan_DotNet()
=> TimeSpan.FromMilliseconds(_milliseconds);
=> TimeSpan.FromSeconds(_second);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ namespace aweXpect.Chronology.Benchmarks;
[MemoryDiagnoser]
public partial class HappyCaseBenchmarks
{
private readonly int _day = 5;
private readonly int _hour = 14;
private readonly int _minute = 2;
private readonly int _month = 7;
private readonly int _second = 16;
private readonly int _year = 1964;
}

0 comments on commit 8fb0a62

Please sign in to comment.