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 static de.uni_marburg.powersort.data.ObjectSupplier.EMPTY_ARRAY;
|
||||
|
||||
// TODO: The parameters are way too low. Use for debugging only!
|
||||
/*
|
||||
* Benchmark parameters
|
||||
*/
|
||||
@Fork(1)
|
||||
@Fork(value = 1, jvmArgsAppend = "-Xmx8g")
|
||||
@Warmup(iterations = 1)
|
||||
@Measurement(iterations = 6)
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@ -42,7 +40,7 @@ public class MainJmh {
|
||||
@Param()
|
||||
private SortEnum sortEnum;
|
||||
|
||||
private ObjectSupplier data = EMPTY_ARRAY;
|
||||
private ObjectSupplier data = null;
|
||||
/* package-protected */ Object[] workingCopy;
|
||||
|
||||
// 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() {
|
||||
if(Filter.isFiltered(dataEnum, sortEnum)) {
|
||||
// This combination of DataEnum and SortEnum should be skipped.
|
||||
// We can't tell JMH to not run the benchmark at all,
|
||||
// so we'll let it sort an empty list instead ;)
|
||||
data = EMPTY_ARRAY;
|
||||
// We can't tell JMH to not run the benchmark at all.
|
||||
// Instead, we let it sort an invalid list which results in an exception.
|
||||
// This way the filtered combinations are skipped quickly
|
||||
// and not included in the benchmark results.
|
||||
data = null;
|
||||
workingCopy = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// A new MainJmh object is created for each @Param variation.
|
||||
// Then, `data` is `null` again.
|
||||
if (data == EMPTY_ARRAY) {
|
||||
if (data == null) {
|
||||
data = dataEnum.getObjectSupplier();
|
||||
}
|
||||
// For all warmup and measurement iterations of one @Param variation, the MainJmh object is reused.
|
||||
|
@ -24,7 +24,12 @@ public class Filter {
|
||||
// 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(List.of(
|
||||
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.data.ObjectSupplier;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -12,8 +11,8 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(final String[] args) {
|
||||
final EnumSet<SortEnum> sortImplementations = getSortImplementations();
|
||||
final EnumSet<DataEnum> dataEnums = getSortInputSuppliers();
|
||||
final SortEnum[] sortImplementations = SortEnum.values();
|
||||
final DataEnum[] dataEnums = DataEnum.values();
|
||||
|
||||
System.out.println();
|
||||
for (DataEnum dataEnum : dataEnums) {
|
||||
@ -48,17 +47,4 @@ public class Main {
|
||||
|
||||
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;
|
||||
|
||||
public abstract class ObjectSupplier {
|
||||
public static final ObjectSupplier EMPTY_ARRAY = new ObjectSupplier(new Object[0]) {};
|
||||
|
||||
/* package-protected */ final Object[] readOnly;
|
||||
|
||||
ObjectSupplier(Object[] readOnly) {
|
||||
@ -17,4 +15,9 @@ public abstract class ObjectSupplier {
|
||||
public Object[] getCopy(){
|
||||
return Arrays.copyOf(readOnly, readOnly.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ObjectSupplier{" + readOnly.length + "}";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user