mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
benchmark: JMH SortEnum
This commit is contained in:
parent
060ff596b8
commit
e3b90c83cc
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
// 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();
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user