benchmark: refactor

This commit is contained in:
Daniel Langbein 2024-12-17 08:34:57 +00:00
parent c3ecfc5531
commit 6b0a5394b1
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
6 changed files with 8 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -16,7 +16,7 @@ public class Main {
final EnumSet<DataEnum> 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;

View File

@ -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';

View File

@ -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);

View File

@ -1,5 +1,5 @@
package de.uni_marburg.powersort.sort;
public interface SimpleSort {
public interface SortImpl {
void sort(Object[] list);
}

View File

@ -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);
}
}