From 68d86d6e6b3d4c3c7c3a095f20e6d6479c17606f Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 17 Dec 2024 18:56:55 +0000 Subject: [PATCH] benchmark: filter out some of the "data x algorithm" combinations --- .../powersort/benchmark/MainJmh.java | 14 ++++++- .../powersort/benchmark/Filter.java | 40 +++++++++++++++++++ .../uni_marburg/powersort/benchmark/Main.java | 34 ++++++++++------ .../powersort/data/ObjectSupplier.java | 2 + 4 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/de/uni_marburg/powersort/benchmark/Filter.java diff --git a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java index 6c194c1..c806c34 100644 --- a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java +++ b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/MainJmh.java @@ -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. diff --git a/app/src/main/java/de/uni_marburg/powersort/benchmark/Filter.java b/app/src/main/java/de/uni_marburg/powersort/benchmark/Filter.java new file mode 100644 index 0000000..023403c --- /dev/null +++ b/app/src/main/java/de/uni_marburg/powersort/benchmark/Filter.java @@ -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; + } +} diff --git a/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java b/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java index 90431f0..29a88b0 100644 --- a/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java +++ b/app/src/main/java/de/uni_marburg/powersort/benchmark/Main.java @@ -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 getSortImplementations() { return EnumSet.allOf(SortEnum.class); } diff --git a/app/src/main/java/de/uni_marburg/powersort/data/ObjectSupplier.java b/app/src/main/java/de/uni_marburg/powersort/data/ObjectSupplier.java index f4c1fa8..5805157 100644 --- a/app/src/main/java/de/uni_marburg/powersort/data/ObjectSupplier.java +++ b/app/src/main/java/de/uni_marburg/powersort/data/ObjectSupplier.java @@ -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) {