Skip to content

Commit

Permalink
Merge pull request #593 from focus-shift/improve-benchmark
Browse files Browse the repository at this point in the history
Use state in benchmarks for year and localdate
  • Loading branch information
derTobsch authored Jul 23, 2024
2 parents 1a9673d + 0d291d1 commit ed7d815
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ public class HolidayManagerGetHolidayBenchmarkTest extends Benchmarks {

private static final double REFERENCE_SCORE = 22_000_000.00;

@State(Scope.Thread)
public static class YearState {
public final Year year = Year.of(2010);
}

@Benchmark
public static Set<Holiday> benchmarkGetHolidays(final HolidayManagerState holidayManagerState) {
return holidayManagerState.holidayManager.getHolidays(Year.of(2010));
public static Set<Holiday> benchmarkGetHolidays(final HolidayManagerState holidayManagerState, final YearState yearState) {
return holidayManagerState.holidayManager.getHolidays(yearState.year);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ public static class HolidayManagerState {
public final HolidayManager holidayManager = HolidayManager.getInstance(create("test"));
}

@State(Scope.Thread)
public static class LocalDateState {
public final LocalDate localDate = LocalDate.of(2010, 1, 1);
}

@Benchmark
public static boolean benchmarkIsHoliday(final HolidayManagerState holidayManagerState) {
return holidayManagerState.holidayManager.isHoliday(LocalDate.of(2010, 1, 1));
public static boolean benchmarkIsHoliday(final HolidayManagerState holidayManagerState, final LocalDateState localDateState) {
return holidayManagerState.holidayManager.isHoliday(localDateState.localDate);
}

@Test
Expand Down

0 comments on commit ed7d815

Please sign in to comment.