mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-22 19:55:44 +01:00
benchmark: refactor
This commit is contained in:
parent
c3ecfc5531
commit
6b0a5394b1
@ -49,7 +49,7 @@ public class MainJmh {
|
|||||||
// A new MainJmh object is created for each @Param variation.
|
// A new MainJmh object is created for each @Param variation.
|
||||||
// Then, `data` is `null` again.
|
// Then, `data` is `null` again.
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
data = dataEnum.get();
|
data = dataEnum.getObjectSupplier();
|
||||||
}
|
}
|
||||||
// For all warmup and measurement iterations of one @Param variation, the MainJmh object is reused.
|
// For all warmup and measurement iterations of one @Param variation, the MainJmh object is reused.
|
||||||
// Thus, we can't just sort `data` directly.
|
// Thus, we can't just sort `data` directly.
|
||||||
@ -60,6 +60,6 @@ public class MainJmh {
|
|||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public void benchmark() {
|
public void benchmark() {
|
||||||
sortEnum.get().sort(workingCopy);
|
sortEnum.getSortImpl().sort(workingCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class Main {
|
|||||||
final EnumSet<DataEnum> dataEnums = getSortInputSuppliers();
|
final EnumSet<DataEnum> dataEnums = getSortInputSuppliers();
|
||||||
|
|
||||||
for (DataEnum dataEnum : dataEnums) {
|
for (DataEnum dataEnum : dataEnums) {
|
||||||
ObjectSupplier objectSupplier = dataEnum.get();
|
ObjectSupplier objectSupplier = dataEnum.getObjectSupplier();
|
||||||
System.out.println(dataEnum);
|
System.out.println(dataEnum);
|
||||||
|
|
||||||
for (SortEnum sortImplementation : sortImplementations) {
|
for (SortEnum sortImplementation : sortImplementations) {
|
||||||
@ -24,7 +24,7 @@ public class Main {
|
|||||||
|
|
||||||
// TODO: JVM warmup!
|
// TODO: JVM warmup!
|
||||||
final long startNanos = System.nanoTime();
|
final long startNanos = System.nanoTime();
|
||||||
sortImplementation.get().sort(sortInput);
|
sortImplementation.getSortImpl().sort(sortInput);
|
||||||
final long stopNanos = System.nanoTime();
|
final long stopNanos = System.nanoTime();
|
||||||
|
|
||||||
final long durNanos = stopNanos - startNanos;
|
final long durNanos = stopNanos - startNanos;
|
||||||
|
@ -7,7 +7,7 @@ public enum DataEnum {
|
|||||||
ASCENDING_RUNS,
|
ASCENDING_RUNS,
|
||||||
ASCENDING_RUNS_WITH_OVERLAP;
|
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!
|
// 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 = 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';
|
final long seed = 140506881906827520L; // (long) 'P' * (long) 'O' *(long) 'W' * (long) 'E' * (long) 'R' * (long) 'S' * (long) 'O' * (long) 'R' * (long) 'T';
|
||||||
|
@ -10,7 +10,7 @@ public enum SortEnum {
|
|||||||
FIN_SORT,
|
FIN_SORT,
|
||||||
ASORT;
|
ASORT;
|
||||||
|
|
||||||
public SimpleSort get() {
|
public SortImpl getSortImpl() {
|
||||||
return switch (this) {
|
return switch (this) {
|
||||||
// case BUBBLE_SORT -> array -> BubbleSort.sort(array, NaturalOrder.INSTANCE);
|
// case BUBBLE_SORT -> array -> BubbleSort.sort(array, NaturalOrder.INSTANCE);
|
||||||
case MERGE_SORT -> array -> MergeSort.legacyMergeSort(array, NaturalOrder.INSTANCE);
|
case MERGE_SORT -> array -> MergeSort.legacyMergeSort(array, NaturalOrder.INSTANCE);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package de.uni_marburg.powersort.sort;
|
package de.uni_marburg.powersort.sort;
|
||||||
|
|
||||||
public interface SimpleSort {
|
public interface SortImpl {
|
||||||
void sort(Object[] list);
|
void sort(Object[] list);
|
||||||
}
|
}
|
@ -51,7 +51,7 @@ public abstract class AbstractSortTest {
|
|||||||
Integer[] expected = Arrays.copyOf(array, array.length);
|
Integer[] expected = Arrays.copyOf(array, array.length);
|
||||||
Arrays.sort(expected);
|
Arrays.sort(expected);
|
||||||
|
|
||||||
sortAlg.get().sort(array);
|
sortAlg.getSortImpl().sort(array);
|
||||||
assertArrayEquals(expected, array);
|
assertArrayEquals(expected, array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user