diff --git a/app/src/main/java/de/uni_marburg/powersort/benchmark/SomeComparable.java b/app/src/main/java/de/uni_marburg/powersort/benchmark/DummyComparable1.java similarity index 53% rename from app/src/main/java/de/uni_marburg/powersort/benchmark/SomeComparable.java rename to app/src/main/java/de/uni_marburg/powersort/benchmark/DummyComparable1.java index 85823ad..7cea94b 100644 --- a/app/src/main/java/de/uni_marburg/powersort/benchmark/SomeComparable.java +++ b/app/src/main/java/de/uni_marburg/powersort/benchmark/DummyComparable1.java @@ -3,9 +3,9 @@ package de.uni_marburg.powersort.benchmark; /** * A class for tiny, comparable objects. */ -record SomeComparable(int id) implements Comparable { +record DummyComparable1(int id) implements Comparable { @Override - public int compareTo(SomeComparable other) { + public int compareTo(DummyComparable1 other) { return id - other.id; } } diff --git a/app/src/main/java/de/uni_marburg/powersort/benchmark/DummyComparable2.java b/app/src/main/java/de/uni_marburg/powersort/benchmark/DummyComparable2.java new file mode 100644 index 0000000..59f35a4 --- /dev/null +++ b/app/src/main/java/de/uni_marburg/powersort/benchmark/DummyComparable2.java @@ -0,0 +1,18 @@ +package de.uni_marburg.powersort.benchmark; + +/** + * A class for tiny, comparable objects. + *

+ * Prints to stdout when an object is created. + */ +record DummyComparable2(int id) implements Comparable { + public DummyComparable2(int id) { + this.id = id; + System.out.println("Initialized " + this); + } + + @Override + public int compareTo(DummyComparable2 other) { + return id - other.id; + } +} diff --git a/app/src/main/java/de/uni_marburg/powersort/benchmark/Educational.java b/app/src/main/java/de/uni_marburg/powersort/benchmark/Educational.java index 2f35045..22c13b2 100644 --- a/app/src/main/java/de/uni_marburg/powersort/benchmark/Educational.java +++ b/app/src/main/java/de/uni_marburg/powersort/benchmark/Educational.java @@ -24,9 +24,9 @@ public class Educational { * eliminate the code duplication. */ private static void sortObjectsAvoidingComparableTimSort() { - SomeComparable[] a = { - new SomeComparable(1), - new SomeComparable(0) + DummyComparable1[] a = { + new DummyComparable1(1), + new DummyComparable1(0) }; NaturalOrder c = NaturalOrder.INSTANCE; @@ -38,9 +38,9 @@ public class Educational { } public static void sortObjects() { - SomeComparable[] a = { - new SomeComparable(1), - new SomeComparable(0) + DummyComparable1[] a = { + new DummyComparable1(1), + new DummyComparable1(0) }; 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 907d402..99abb3a 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,20 +4,21 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Comparator; +import java.util.List; +import java.util.function.Supplier; public class Main { public static void main(final String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { - final SomeComparable[] a = { - new SomeComparable(1), - new SomeComparable(0) - }; - final Method[] sortImplementations = getSortImplementations(); + final List> sortInputSuppliers = getSortInputSuppliers(); final NaturalOrder c = NaturalOrder.INSTANCE; - for (Method sortImplementation : sortImplementations) { - sortImplementation.invoke(null, a, 0, 0, c, null, 0, 0); - System.out.println(Arrays.toString(a)); + for (Supplier sortInputSupplier : sortInputSuppliers) { + for (Method sortImplementation : sortImplementations) { + Object[] sortInput = sortInputSupplier.get(); + sortImplementation.invoke(null, sortInput, 0, 0, c, null, 0, 0); + System.out.println(Arrays.toString(sortInput)); + } } } @@ -27,4 +28,11 @@ public class Main { DummySort2.class.getMethod("sort", Object[].class, int.class, int.class, Comparator.class, Object[].class, int.class, int.class) }; } + + static List> getSortInputSuppliers() { + return Arrays.asList( + () -> new DummyComparable2[]{new DummyComparable2(0), new DummyComparable2(1)}, + () -> new DummyComparable2[]{new DummyComparable2(2), new DummyComparable2(3)} + ); + } }