Created
November 21, 2017 02:45
-
-
Save jdaigle/a82645a1adcf42dd80bb1b5e385c0444 to your computer and use it in GitHub Desktop.
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
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