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 c806c34..f678db8 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,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. 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 index 0547850..a3d401f 100644 --- a/app/src/main/java/de/uni_marburg/powersort/benchmark/Filter.java +++ b/app/src/main/java/de/uni_marburg/powersort/benchmark/Filter.java @@ -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, 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 2045149..8eb858b 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 @@ -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,15 +11,15 @@ import java.util.concurrent.TimeUnit; */ public class Main { public static void main(final String[] args) { - final EnumSet sortImplementations = getSortImplementations(); - final EnumSet dataEnums = getSortInputSuppliers(); + final SortEnum[] sortImplementations = SortEnum.values(); + final DataEnum[] dataEnums = DataEnum.values(); System.out.println(); for (DataEnum dataEnum : dataEnums) { ObjectSupplier objectSupplier = null; for (SortEnum sortImplementation : sortImplementations) { - if(!Filter.isFiltered(dataEnum, sortImplementation)) { - if(objectSupplier == null){ + if (!Filter.isFiltered(dataEnum, sortImplementation)) { + if (objectSupplier == null) { System.out.println("⏳ Creating object supplier " + dataEnum + " ⏳"); 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.flush(); Object[] sortInput = objectSupplier.getCopy(); @@ -48,17 +47,4 @@ public class Main { System.out.println("," + durFormatted); } - - static EnumSet 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 getSortInputSuppliers() { - return EnumSet.allOf(DataEnum.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 5805157..f2814cd 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,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 + "}"; + } }