mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-22 19:55:44 +01:00
benchmark preparations
This commit is contained in:
parent
0b5c6df766
commit
b08816b9a4
@ -3,9 +3,9 @@ package de.uni_marburg.powersort.benchmark;
|
|||||||
/**
|
/**
|
||||||
* A class for tiny, comparable objects.
|
* A class for tiny, comparable objects.
|
||||||
*/
|
*/
|
||||||
record SomeComparable(int id) implements Comparable<SomeComparable> {
|
record DummyComparable1(int id) implements Comparable<DummyComparable1> {
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(SomeComparable other) {
|
public int compareTo(DummyComparable1 other) {
|
||||||
return id - other.id;
|
return id - other.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -24,9 +24,9 @@ public class Educational {
|
|||||||
* eliminate the code duplication.
|
* eliminate the code duplication.
|
||||||
*/
|
*/
|
||||||
private static void sortObjectsAvoidingComparableTimSort() {
|
private static void sortObjectsAvoidingComparableTimSort() {
|
||||||
SomeComparable[] a = {
|
DummyComparable1[] a = {
|
||||||
new SomeComparable(1),
|
new DummyComparable1(1),
|
||||||
new SomeComparable(0)
|
new DummyComparable1(0)
|
||||||
};
|
};
|
||||||
|
|
||||||
NaturalOrder c = NaturalOrder.INSTANCE;
|
NaturalOrder c = NaturalOrder.INSTANCE;
|
||||||
@ -38,9 +38,9 @@ public class Educational {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sortObjects() {
|
public static void sortObjects() {
|
||||||
SomeComparable[] a = {
|
DummyComparable1[] a = {
|
||||||
new SomeComparable(1),
|
new DummyComparable1(1),
|
||||||
new SomeComparable(0)
|
new DummyComparable1(0)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,20 +4,21 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(final String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
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 Method[] sortImplementations = getSortImplementations();
|
||||||
|
final List<Supplier<Object[]>> sortInputSuppliers = getSortInputSuppliers();
|
||||||
|
|
||||||
final NaturalOrder c = NaturalOrder.INSTANCE;
|
final NaturalOrder c = NaturalOrder.INSTANCE;
|
||||||
for (Method sortImplementation : sortImplementations) {
|
for (Supplier<Object[]> sortInputSupplier : sortInputSuppliers) {
|
||||||
sortImplementation.invoke(null, a, 0, 0, c, null, 0, 0);
|
for (Method sortImplementation : sortImplementations) {
|
||||||
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)
|
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)}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user