Skip to content

Instantly share code, notes, and snippets.

@jdaigle
Created November 21, 2017 02:45
Show Gist options
  • Save jdaigle/a82645a1adcf42dd80bb1b5e385c0444 to your computer and use it in GitHub Desktop.
Save jdaigle/a82645a1adcf42dd80bb1b5e385c0444 to your computer and use it in GitHub Desktop.
public class DateComparisonBenchmarks
{
private DateTime _dateTimeA;
private DateTime _dateTimeB;
private LocalDate _localDateA;
private LocalDate _localDateB;
[GlobalSetup]
public void GlobalSetup()
{
_dateTimeA = new DateTime(2017, 05, 02);
_dateTimeB = new DateTime(2017, 05, 03);
_localDateA = LocalDate.FromDateTime(_dateTimeA);
_localDateB = LocalDate.FromDateTime(_dateTimeB);
}
[Benchmark(Baseline= true)]
public bool Compare_DateTime()
{
return _dateTimeA.CompareTo(_dateTimeB) > 0;
}
[Benchmark]
public bool Compare_NodaTime()
{
return _localDateA.CompareTo(_localDateB) > 0;
}
[Benchmark]
public bool Compare_Operator_DateTime()
{
return _dateTimeA > _dateTimeB;
}
[Benchmark]
public bool Compare_Operator_NodaTime()
{
return _localDateA > _localDateB;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment