benchmark: JMH SortEnum

This commit is contained in:
Daniel Langbein 2024-12-11 18:05:12 +00:00
parent 060ff596b8
commit e3b90c83cc
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
3 changed files with 10 additions and 34 deletions

View File

@ -1,10 +0,0 @@
package de.uni_marburg.powersort.benchmark;
import de.uni_marburg.powersort.sort.DummySort;
public class DummySortBenchmark extends AbstractBenchmark {
@Override
public void sort() {
DummySort.sort(workingCopy, 0, workingCopy.length, NaturalOrder.INSTANCE, null, 0, 0);
}
}

View File

@ -2,6 +2,7 @@ package de.uni_marburg.powersort.benchmark;
import de.uni_marburg.powersort.data.DataEnum;
import de.uni_marburg.powersort.data.ObjectSupplier;
import de.uni_marburg.powersort.sort.SortEnum;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
@ -33,33 +34,28 @@ import java.util.concurrent.TimeUnit;
* State objects naturally encapsulate the state on which benchmark is working on.
*/
@State(Scope.Benchmark)
public abstract class AbstractBenchmark {
public class MainJmh {
@Param()
private DataEnum dataEnum;
@Param()
private SortEnum sortEnum;
private DataEnum prevDataEnum = null;
private ObjectSupplier data;
/* package-protected */ Object[] workingCopy;
// TODO: This is inaccurate. How to create and use separate arrays for each warmup x iteration x sortAlgorithm ?
@Setup(Level.Invocation)
public void setup() {
if (dataEnum != prevDataEnum){
System.out.println(prevDataEnum + " => " + dataEnum);
prevDataEnum = dataEnum;
data = dataEnum.get();
}
// TODO: We tried to store the old `dataEnum` in a separate variable and only call `dataEnum.get()` if `dataEnum` changed. But the separate variable was always reverted to `null`. Why? Maybe as the benchmark method does not use it?
// TODO: This leads to different random lists used for each sort impl.
//
// TODO: This is better anyways: Store random list on disk and reuse it for reproducibility
data = dataEnum.get();
workingCopy = data.getCopy();
}
@Benchmark
public void benchmark() {
sort();
sortEnum.get().sort(workingCopy);
}
/**
* Sorts this.array with some sorting algorithm.
*/
/* package-protected */ abstract void sort();
}

View File

@ -1,10 +0,0 @@
package de.uni_marburg.powersort.benchmark;
import de.uni_marburg.powersort.sort.MergeSort;
public class MergeSortBenchmark extends AbstractBenchmark {
@Override
public void sort() {
MergeSort.legacyMergeSort(workingCopy, NaturalOrder.INSTANCE);
}
}