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
e627c99b55
commit
684f28bb2b
@ -9,45 +9,43 @@ import org.openjdk.jmh.annotations.*;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
// TODO: The parameters are way too low. Use for debugging only!
|
// TODO: The parameters are way too low. Use for debugging only!
|
||||||
@Fork(1)
|
/*
|
||||||
@Warmup(iterations = 3)
|
* Benchmark parameters
|
||||||
@Measurement(iterations = 6)
|
*/
|
||||||
public class BenchmarkJmh {
|
@Fork(0)
|
||||||
/**
|
@Warmup(iterations = 0)
|
||||||
|
@Measurement(iterations = 1)
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||||
|
/*
|
||||||
|
* Benchmark state parameters
|
||||||
|
*
|
||||||
* Quote from JMH:
|
* Quote from JMH:
|
||||||
* 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 static class State1 {
|
public class BenchmarkJmh {
|
||||||
RandomIntegers d = new RandomIntegers();
|
private final RandomIntegers readonly = new RandomIntegers();
|
||||||
Integer[] a;
|
/* package-protected */ Integer[] array;
|
||||||
|
|
||||||
// TODO: This is inaccurate.
|
// TODO: This is inaccurate. How to create and use separate arrays for each warmup x iteration x sortAlgorithm ?
|
||||||
// How to create and use separate arrays for each warmup x iteration x sortAlgorithm ?
|
|
||||||
@Setup(Level.Invocation)
|
@Setup(Level.Invocation)
|
||||||
public void setup() {
|
public void setup() {
|
||||||
a = d.get();
|
array = readonly.getCopy();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
|
||||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public void rand1DummySort(State1 s) {
|
public void rand1DummySort() {
|
||||||
DummySort.sort(s.a, 0, s.a.length, NaturalOrder.INSTANCE, null, 0, 0);
|
DummySort.sort(array, 0, array.length, NaturalOrder.INSTANCE, null, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
|
||||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public void rand1TimSort(State1 s) {
|
public void rand1TimSort() {
|
||||||
TimSort.sort(s.a, 0, s.a.length, NaturalOrder.INSTANCE, null, 0, 0);
|
TimSort.sort(array, 0, array.length, NaturalOrder.INSTANCE, null, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
|
||||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public void rand1MergeSort(State1 s) {
|
public void rand1MergeSort() {
|
||||||
MergeSort.legacyMergeSort(s.a, NaturalOrder.INSTANCE);
|
MergeSort.legacyMergeSort(array, NaturalOrder.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class Main {
|
|||||||
System.out.println("\n" + objectSupplier.title());
|
System.out.println("\n" + objectSupplier.title());
|
||||||
|
|
||||||
for (SortImpl sortImplementation : sortImplementations) {
|
for (SortImpl sortImplementation : sortImplementations) {
|
||||||
Object[] sortInput = objectSupplier.get();
|
Object[] sortInput = objectSupplier.getCopy();
|
||||||
|
|
||||||
final long startNanos = System.nanoTime();
|
final long startNanos = System.nanoTime();
|
||||||
sortImplementation.sort(sortInput);
|
sortImplementation.sort(sortInput);
|
||||||
|
@ -6,7 +6,7 @@ public abstract class IntegerSupplier extends ObjectSupplier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer[] get() {
|
public Integer[] getCopy() {
|
||||||
return (Integer[]) super.get();
|
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.
|
* @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);
|
return Arrays.copyOf(readOnly, readOnly.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user