From 6b0a5394b19115584a362134c8fad3a37403c9b8 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 17 Dec 2024 08:34:57 +0000 Subject: [PATCH] benchmark: refactor --- .../jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java | 4 ++-- .../main/java/de/uni_marburg/powersort/benchmark/Main.java | 4 ++-- app/src/main/java/de/uni_marburg/powersort/data/DataEnum.java | 2 +- app/src/main/java/de/uni_marburg/powersort/sort/SortEnum.java | 2 +- .../powersort/sort/{SimpleSort.java => SortImpl.java} | 2 +- .../java/de/uni_marburg/powersort/sort/AbstractSortTest.java | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename app/src/main/java/de/uni_marburg/powersort/sort/{SimpleSort.java => SortImpl.java} (70%) diff --git a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java index d0151f6..31cb83e 100644 --- a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java +++ b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java @@ -49,7 +49,7 @@ public class MainJmh { // A new MainJmh object is created for each @Param variation. // Then, `data` is `null` again. if (data == null) { - data = dataEnum.get(); + data = dataEnum.getObjectSupplier(); } // For all warmup and measurement iterations of one @Param variation, the MainJmh object is reused. // Thus, we can't just sort `data` directly. @@ -60,6 +60,6 @@ public class MainJmh { @Benchmark public void benchmark() { - sortEnum.get().sort(workingCopy); + sortEnum.getSortImpl().sort(workingCopy); } } diff --git a/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java b/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java index 5335757..917446f 100644 --- a/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java +++ b/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java @@ -16,7 +16,7 @@ public class Main { final EnumSet dataEnums = getSortInputSuppliers(); for (DataEnum dataEnum : dataEnums) { - ObjectSupplier objectSupplier = dataEnum.get(); + ObjectSupplier objectSupplier = dataEnum.getObjectSupplier(); System.out.println(dataEnum); for (SortEnum sortImplementation : sortImplementations) { @@ -24,7 +24,7 @@ public class Main { // TODO: JVM warmup! final long startNanos = System.nanoTime(); - sortImplementation.get().sort(sortInput); + sortImplementation.getSortImpl().sort(sortInput); final long stopNanos = System.nanoTime(); final long durNanos = stopNanos - startNanos; diff --git a/app/src/main/java/de/uni_marburg/powersort/data/DataEnum.java b/app/src/main/java/de/uni_marburg/powersort/data/DataEnum.java index ff9de0a..243f838 100644 --- a/app/src/main/java/de/uni_marburg/powersort/data/DataEnum.java +++ b/app/src/main/java/de/uni_marburg/powersort/data/DataEnum.java @@ -7,7 +7,7 @@ public enum DataEnum { ASCENDING_RUNS, ASCENDING_RUNS_WITH_OVERLAP; - public ObjectSupplier get() { + public ObjectSupplier getObjectSupplier() { // We use a seed to get the same random list every time -> Repeatable benchmarks on same input data! // final long seed = 3651660232967549736L; // System.nanoTime() ++ Math.random() final long seed = 140506881906827520L; // (long) 'P' * (long) 'O' *(long) 'W' * (long) 'E' * (long) 'R' * (long) 'S' * (long) 'O' * (long) 'R' * (long) 'T'; diff --git a/app/src/main/java/de/uni_marburg/powersort/sort/SortEnum.java b/app/src/main/java/de/uni_marburg/powersort/sort/SortEnum.java index f2c6bfe..1b636d9 100644 --- a/app/src/main/java/de/uni_marburg/powersort/sort/SortEnum.java +++ b/app/src/main/java/de/uni_marburg/powersort/sort/SortEnum.java @@ -10,7 +10,7 @@ public enum SortEnum { FIN_SORT, ASORT; - public SimpleSort get() { + public SortImpl getSortImpl() { return switch (this) { // case BUBBLE_SORT -> array -> BubbleSort.sort(array, NaturalOrder.INSTANCE); case MERGE_SORT -> array -> MergeSort.legacyMergeSort(array, NaturalOrder.INSTANCE); diff --git a/app/src/main/java/de/uni_marburg/powersort/sort/SimpleSort.java b/app/src/main/java/de/uni_marburg/powersort/sort/SortImpl.java similarity index 70% rename from app/src/main/java/de/uni_marburg/powersort/sort/SimpleSort.java rename to app/src/main/java/de/uni_marburg/powersort/sort/SortImpl.java index 79e993e..c47ec39 100644 --- a/app/src/main/java/de/uni_marburg/powersort/sort/SimpleSort.java +++ b/app/src/main/java/de/uni_marburg/powersort/sort/SortImpl.java @@ -1,5 +1,5 @@ package de.uni_marburg.powersort.sort; -public interface SimpleSort { +public interface SortImpl { void sort(Object[] list); } diff --git a/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java b/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java index aba63c0..09c771a 100644 --- a/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java +++ b/app/src/test/java/de/uni_marburg/powersort/sort/AbstractSortTest.java @@ -51,7 +51,7 @@ public abstract class AbstractSortTest { Integer[] expected = Arrays.copyOf(array, array.length); Arrays.sort(expected); - sortAlg.get().sort(array); + sortAlg.getSortImpl().sort(array); assertArrayEquals(expected, array); } }