mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
benchmark: filter out some of the "data x algorithm" combinations
This commit is contained in:
parent
9bb9096c92
commit
68d86d6e6b
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -17,10 +17,22 @@ 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) {
|
||||
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!
|
||||
@ -31,10 +43,8 @@ public class Main {
|
||||
final long durNanos = stopNanos - startNanos;
|
||||
final long durMillis = TimeUnit.NANOSECONDS.toMillis(durNanos);
|
||||
final String durFormatted = LongFormatter.formatUnderscore(durMillis);
|
||||
System.out.println(durFormatted + "," + sortImplementation);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.println("," + durFormatted);
|
||||
}
|
||||
|
||||
static EnumSet<SortEnum> getSortImplementations() {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user