benchmark: filter out some of the "data x algorithm" combinations

This commit is contained in:
Daniel Langbein 2024-12-17 18:56:55 +00:00
parent 9bb9096c92
commit 68d86d6e6b
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
4 changed files with 76 additions and 14 deletions

View File

@ -18,6 +18,8 @@ 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
@ -40,15 +42,23 @@ public class MainJmh {
@Param()
private SortEnum sortEnum;
private ObjectSupplier data;
private ObjectSupplier data = EMPTY_ARRAY;
/* package-protected */ Object[] workingCopy;
// TODO: This is inaccurate. How to create and use separate arrays for each warmup x iteration x sortAlgorithm ?
@Setup(Level.Invocation)
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;
return;
}
// A new MainJmh object is created for each @Param variation.
// Then, `data` is `null` again.
if (data == null) {
if (data == EMPTY_ARRAY) {
data = dataEnum.getObjectSupplier();
}
// For all warmup and measurement iterations of one @Param variation, the MainJmh object is reused.

View File

@ -0,0 +1,40 @@
package de.uni_marburg.powersort.benchmark;
import de.uni_marburg.powersort.data.DataEnum;
import de.uni_marburg.powersort.sort.SortEnum;
import java.util.List;
public class Filter {
/* Utility Class */
private Filter() {
}
public static boolean isFiltered(DataEnum d, SortEnum s) {
if (s == SortEnum.MERGE_SORT) {
return List.of(
DataEnum.RANDOM_INTEGERS_300M,
DataEnum.ASCENDING_INTEGERS_300M,
DataEnum.DESCENDING_INTEGERS_250M
).contains(d);
}
if (s == SortEnum.BUBBLE_SORT) {
return List.of(
DataEnum.DESCENDING_INTEGERS_250M,
DataEnum.ASCENDING_RUNS_1M,
DataEnum.ASCENDING_RUNS_WITH_OVERLAP_1M
).contains(d);
}
// TODO: Remove this once performance of FinnSort improved
if (s == SortEnum.FINN_SORT) {
return List.of(
DataEnum.DESCENDING_INTEGERS_250M
).contains(d);
}
return false;
}
}

View File

@ -17,26 +17,36 @@ public class Main {
System.out.println();
for (DataEnum dataEnum : dataEnums) {
System.out.println("⏳ Creating object supplier " + dataEnum + "");
ObjectSupplier objectSupplier = dataEnum.getObjectSupplier();
System.out.println(dataEnum);
for (SortEnum sortImplementation : sortImplementations) {
Object[] sortInput = objectSupplier.getCopy();
// TODO: JVM warmup!
final long startNanos = System.nanoTime();
sortImplementation.getSortImpl().sort(sortInput);
final long stopNanos = System.nanoTime();
final long durNanos = stopNanos - startNanos;
final long durMillis = TimeUnit.NANOSECONDS.toMillis(durNanos);
final String durFormatted = LongFormatter.formatUnderscore(durMillis);
System.out.println(durFormatted + "," + sortImplementation);
if(!Filter.isFiltered(dataEnum, sortImplementation)) {
benchmark(objectSupplier, sortImplementation);
}
}
System.out.println();
}
}
static void benchmark(ObjectSupplier objectSupplier, SortEnum sortImplementation){
System.out.print(sortImplementation);
System.out.flush();
Object[] sortInput = objectSupplier.getCopy();
// TODO: JVM warmup!
final long startNanos = System.nanoTime();
sortImplementation.getSortImpl().sort(sortInput);
final long stopNanos = System.nanoTime();
final long durNanos = stopNanos - startNanos;
final long durMillis = TimeUnit.NANOSECONDS.toMillis(durNanos);
final String durFormatted = LongFormatter.formatUnderscore(durMillis);
System.out.println("," + durFormatted);
}
static EnumSet<SortEnum> getSortImplementations() {
return EnumSet.allOf(SortEnum.class);
}

View File

@ -3,6 +3,8 @@ 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) {