mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
benchmark: cleanup
This commit is contained in:
parent
54f3ea6d42
commit
4223f76727
@ -18,13 +18,11 @@ import org.openjdk.jmh.annotations.Warmup;
|
|||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static de.uni_marburg.powersort.data.ObjectSupplier.EMPTY_ARRAY;
|
|
||||||
|
|
||||||
// TODO: The parameters are way too low. Use for debugging only!
|
// TODO: The parameters are way too low. Use for debugging only!
|
||||||
/*
|
/*
|
||||||
* Benchmark parameters
|
* Benchmark parameters
|
||||||
*/
|
*/
|
||||||
@Fork(1)
|
@Fork(value = 1, jvmArgsAppend = "-Xmx8g")
|
||||||
@Warmup(iterations = 1)
|
@Warmup(iterations = 1)
|
||||||
@Measurement(iterations = 6)
|
@Measurement(iterations = 6)
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
@ -42,7 +40,7 @@ public class MainJmh {
|
|||||||
@Param()
|
@Param()
|
||||||
private SortEnum sortEnum;
|
private SortEnum sortEnum;
|
||||||
|
|
||||||
private ObjectSupplier data = EMPTY_ARRAY;
|
private ObjectSupplier data = null;
|
||||||
/* package-protected */ Object[] workingCopy;
|
/* package-protected */ Object[] workingCopy;
|
||||||
|
|
||||||
// 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 ?
|
||||||
@ -50,15 +48,18 @@ public class MainJmh {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
if(Filter.isFiltered(dataEnum, sortEnum)) {
|
if(Filter.isFiltered(dataEnum, sortEnum)) {
|
||||||
// This combination of DataEnum and SortEnum should be skipped.
|
// This combination of DataEnum and SortEnum should be skipped.
|
||||||
// We can't tell JMH to not run the benchmark at all,
|
// We can't tell JMH to not run the benchmark at all.
|
||||||
// so we'll let it sort an empty list instead ;)
|
// Instead, we let it sort an invalid list which results in an exception.
|
||||||
data = EMPTY_ARRAY;
|
// This way the filtered combinations are skipped quickly
|
||||||
|
// and not included in the benchmark results.
|
||||||
|
data = null;
|
||||||
|
workingCopy = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A new MainJmh object is created for each @Param variation.
|
// A new MainJmh object is created for each @Param variation.
|
||||||
// Then, `data` is `null` again.
|
// Then, `data` is `null` again.
|
||||||
if (data == EMPTY_ARRAY) {
|
if (data == null) {
|
||||||
data = dataEnum.getObjectSupplier();
|
data = dataEnum.getObjectSupplier();
|
||||||
}
|
}
|
||||||
// For all warmup and measurement iterations of one @Param variation, the MainJmh object is reused.
|
// For all warmup and measurement iterations of one @Param variation, the MainJmh object is reused.
|
||||||
|
@ -24,7 +24,12 @@ public class Filter {
|
|||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Skip some sort algorithms for all competition input data.
|
// To skip all competition inputs, uncomment the next line.
|
||||||
|
// if(d.isCompetitionInput()){
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Skip some sort algorithms for all competition inputs.
|
||||||
if(d.isCompetitionInput()){
|
if(d.isCompetitionInput()){
|
||||||
if(List.of(
|
if(List.of(
|
||||||
SortEnum.BUBBLE_SORT,
|
SortEnum.BUBBLE_SORT,
|
||||||
|
@ -4,7 +4,6 @@ import de.uni_marburg.powersort.data.DataEnum;
|
|||||||
import de.uni_marburg.powersort.sort.SortEnum;
|
import de.uni_marburg.powersort.sort.SortEnum;
|
||||||
import de.uni_marburg.powersort.data.ObjectSupplier;
|
import de.uni_marburg.powersort.data.ObjectSupplier;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,15 +11,15 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(final String[] args) {
|
public static void main(final String[] args) {
|
||||||
final EnumSet<SortEnum> sortImplementations = getSortImplementations();
|
final SortEnum[] sortImplementations = SortEnum.values();
|
||||||
final EnumSet<DataEnum> dataEnums = getSortInputSuppliers();
|
final DataEnum[] dataEnums = DataEnum.values();
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
for (DataEnum dataEnum : dataEnums) {
|
for (DataEnum dataEnum : dataEnums) {
|
||||||
ObjectSupplier objectSupplier = null;
|
ObjectSupplier objectSupplier = null;
|
||||||
for (SortEnum sortImplementation : sortImplementations) {
|
for (SortEnum sortImplementation : sortImplementations) {
|
||||||
if(!Filter.isFiltered(dataEnum, sortImplementation)) {
|
if (!Filter.isFiltered(dataEnum, sortImplementation)) {
|
||||||
if(objectSupplier == null){
|
if (objectSupplier == null) {
|
||||||
System.out.println("⏳ Creating object supplier " + dataEnum + " ⏳");
|
System.out.println("⏳ Creating object supplier " + dataEnum + " ⏳");
|
||||||
objectSupplier = dataEnum.getObjectSupplier();
|
objectSupplier = dataEnum.getObjectSupplier();
|
||||||
}
|
}
|
||||||
@ -32,7 +31,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void benchmark(ObjectSupplier objectSupplier, SortEnum sortImplementation){
|
static void benchmark(ObjectSupplier objectSupplier, SortEnum sortImplementation) {
|
||||||
System.out.print(sortImplementation);
|
System.out.print(sortImplementation);
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
Object[] sortInput = objectSupplier.getCopy();
|
Object[] sortInput = objectSupplier.getCopy();
|
||||||
@ -48,17 +47,4 @@ public class Main {
|
|||||||
|
|
||||||
System.out.println("," + durFormatted);
|
System.out.println("," + durFormatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
static EnumSet<SortEnum> getSortImplementations() {
|
|
||||||
return EnumSet.allOf(SortEnum.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The returned ObjectSupplier objects are wrapped by DataEnum objects.
|
|
||||||
* This way they are lazily created on their first access with DataEnum.get().
|
|
||||||
* This saves memory if we work with large lists.
|
|
||||||
*/
|
|
||||||
static EnumSet<DataEnum> getSortInputSuppliers() {
|
|
||||||
return EnumSet.allOf(DataEnum.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ package de.uni_marburg.powersort.data;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public abstract class ObjectSupplier {
|
public abstract class ObjectSupplier {
|
||||||
public static final ObjectSupplier EMPTY_ARRAY = new ObjectSupplier(new Object[0]) {};
|
|
||||||
|
|
||||||
/* package-protected */ final Object[] readOnly;
|
/* package-protected */ final Object[] readOnly;
|
||||||
|
|
||||||
ObjectSupplier(Object[] readOnly) {
|
ObjectSupplier(Object[] readOnly) {
|
||||||
@ -17,4 +15,9 @@ public abstract class ObjectSupplier {
|
|||||||
public Object[] getCopy(){
|
public Object[] getCopy(){
|
||||||
return Arrays.copyOf(readOnly, readOnly.length);
|
return Arrays.copyOf(readOnly, readOnly.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ObjectSupplier{" + readOnly.length + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user