mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
benchmark: refactor
This commit is contained in:
parent
e627c99b55
commit
684f28bb2b
@ -9,45 +9,43 @@ import org.openjdk.jmh.annotations.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
// TODO: The parameters are way too low. Use for debugging only!
|
||||
@Fork(1)
|
||||
@Warmup(iterations = 3)
|
||||
@Measurement(iterations = 6)
|
||||
public class BenchmarkJmh {
|
||||
/**
|
||||
/*
|
||||
* Benchmark parameters
|
||||
*/
|
||||
@Fork(0)
|
||||
@Warmup(iterations = 0)
|
||||
@Measurement(iterations = 1)
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
/*
|
||||
* Benchmark state parameters
|
||||
*
|
||||
* Quote from JMH:
|
||||
* State objects naturally encapsulate the state on which benchmark is working on.
|
||||
*/
|
||||
@State(Scope.Benchmark)
|
||||
public static class State1 {
|
||||
RandomIntegers d = new RandomIntegers();
|
||||
Integer[] a;
|
||||
public class BenchmarkJmh {
|
||||
private final RandomIntegers readonly = new RandomIntegers();
|
||||
/* package-protected */ Integer[] array;
|
||||
|
||||
// TODO: This is inaccurate.
|
||||
// How to create and use separate arrays for each warmup x iteration x sortAlgorithm ?
|
||||
// TODO: This is inaccurate. How to create and use separate arrays for each warmup x iteration x sortAlgorithm ?
|
||||
@Setup(Level.Invocation)
|
||||
public void setup() {
|
||||
a = d.get();
|
||||
}
|
||||
array = readonly.getCopy();
|
||||
}
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
@Benchmark
|
||||
public void rand1DummySort(State1 s) {
|
||||
DummySort.sort(s.a, 0, s.a.length, NaturalOrder.INSTANCE, null, 0, 0);
|
||||
public void rand1DummySort() {
|
||||
DummySort.sort(array, 0, array.length, NaturalOrder.INSTANCE, null, 0, 0);
|
||||
}
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
@Benchmark
|
||||
public void rand1TimSort(State1 s) {
|
||||
TimSort.sort(s.a, 0, s.a.length, NaturalOrder.INSTANCE, null, 0, 0);
|
||||
public void rand1TimSort() {
|
||||
TimSort.sort(array, 0, array.length, NaturalOrder.INSTANCE, null, 0, 0);
|
||||
}
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
@Benchmark
|
||||
public void rand1MergeSort(State1 s) {
|
||||
MergeSort.legacyMergeSort(s.a, NaturalOrder.INSTANCE);
|
||||
public void rand1MergeSort() {
|
||||
MergeSort.legacyMergeSort(array, NaturalOrder.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class Main {
|
||||
System.out.println("\n" + objectSupplier.title());
|
||||
|
||||
for (SortImpl sortImplementation : sortImplementations) {
|
||||
Object[] sortInput = objectSupplier.get();
|
||||
Object[] sortInput = objectSupplier.getCopy();
|
||||
|
||||
final long startNanos = System.nanoTime();
|
||||
sortImplementation.sort(sortInput);
|
||||
|
@ -6,7 +6,7 @@ public abstract class IntegerSupplier extends ObjectSupplier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer[] get() {
|
||||
return (Integer[]) super.get();
|
||||
public Integer[] getCopy() {
|
||||
return (Integer[]) super.getCopy();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public abstract class ObjectSupplier {
|
||||
/**
|
||||
* @return A fresh copy of the array of objects represented by this object.
|
||||
*/
|
||||
public Object[] get(){
|
||||
public Object[] getCopy(){
|
||||
return Arrays.copyOf(readOnly, readOnly.length);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user