benchmark preparations

This commit is contained in:
Daniel Langbein 2024-12-08 13:09:20 +00:00
parent 0b5c6df766
commit b08816b9a4
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
4 changed files with 42 additions and 16 deletions

View File

@ -3,9 +3,9 @@ package de.uni_marburg.powersort.benchmark;
/**
* A class for tiny, comparable objects.
*/
record SomeComparable(int id) implements Comparable<SomeComparable> {
record DummyComparable1(int id) implements Comparable<DummyComparable1> {
@Override
public int compareTo(SomeComparable other) {
public int compareTo(DummyComparable1 other) {
return id - other.id;
}
}

View File

@ -0,0 +1,18 @@
package de.uni_marburg.powersort.benchmark;
/**
* A class for tiny, comparable objects.
* <p>
* Prints to stdout when an object is created.
*/
record DummyComparable2(int id) implements Comparable<DummyComparable2> {
public DummyComparable2(int id) {
this.id = id;
System.out.println("Initialized " + this);
}
@Override
public int compareTo(DummyComparable2 other) {
return id - other.id;
}
}

View File

@ -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)
};

View File

@ -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<Supplier<Object[]>> sortInputSuppliers = getSortInputSuppliers();
final NaturalOrder c = NaturalOrder.INSTANCE;
for (Supplier<Object[]> sortInputSupplier : sortInputSuppliers) {
for (Method sortImplementation : sortImplementations) {
sortImplementation.invoke(null, a, 0, 0, c, null, 0, 0);
System.out.println(Arrays.toString(a));
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<Supplier<Object[]>> getSortInputSuppliers() {
return Arrays.asList(
() -> new DummyComparable2[]{new DummyComparable2(0), new DummyComparable2(1)},
() -> new DummyComparable2[]{new DummyComparable2(2), new DummyComparable2(3)}
);
}
}