benchmark: refactor

This commit is contained in:
Daniel Langbein 2024-12-11 16:25:47 +00:00
parent 684f28bb2b
commit 605d0c2781
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
3 changed files with 27 additions and 15 deletions

View File

@ -1,8 +1,5 @@
package de.uni_marburg.powersort.benchmark; package de.uni_marburg.powersort.benchmark;
import de.uni_marburg.powersort.sort.DummySort;
import de.uni_marburg.powersort.sort.MergeSort;
import de.uni_marburg.powersort.sort.TimSort;
import de.uni_marburg.powersort.data.RandomIntegers; import de.uni_marburg.powersort.data.RandomIntegers;
import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.annotations.*;
@ -24,7 +21,7 @@ import java.util.concurrent.TimeUnit;
* State objects naturally encapsulate the state on which benchmark is working on. * State objects naturally encapsulate the state on which benchmark is working on.
*/ */
@State(Scope.Benchmark) @State(Scope.Benchmark)
public class BenchmarkJmh { public abstract class AbstractBenchmark {
private final RandomIntegers readonly = new RandomIntegers(); private final RandomIntegers readonly = new RandomIntegers();
/* package-protected */ Integer[] array; /* package-protected */ Integer[] array;
@ -35,17 +32,12 @@ public class BenchmarkJmh {
} }
@Benchmark @Benchmark
public void rand1DummySort() { public void benchmark() {
DummySort.sort(array, 0, array.length, NaturalOrder.INSTANCE, null, 0, 0); sort();
} }
@Benchmark /**
public void rand1TimSort() { * Sorts this.array with some sorting algorithm.
TimSort.sort(array, 0, array.length, NaturalOrder.INSTANCE, null, 0, 0); */
} /* package-protected */ abstract void sort();
@Benchmark
public void rand1MergeSort() {
MergeSort.legacyMergeSort(array, NaturalOrder.INSTANCE);
}
} }

View File

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

View File

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