mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
benchmark: warmup & iterations
This commit is contained in:
parent
82c58e403c
commit
4198e28c79
@ -4,44 +4,52 @@ import de.uni_marburg.powersort.data.DataEnum;
|
|||||||
import de.uni_marburg.powersort.sort.SortEnum;
|
import de.uni_marburg.powersort.sort.SortEnum;
|
||||||
import de.uni_marburg.powersort.data.ObjectSupplier;
|
import de.uni_marburg.powersort.data.ObjectSupplier;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Benchmark (CBM).
|
* Custom Benchmark (CBM).
|
||||||
*/
|
*/
|
||||||
public class CbmBase {
|
public class CbmBase implements Runnable {
|
||||||
static void run(SortEnum[] sortImplementations, DataEnum[] dataEnums) {
|
private final SortEnum[] sortImplementations;
|
||||||
|
private final DataEnum[] dataEnums;
|
||||||
|
private final int maxDataEnumStrLen;
|
||||||
|
private final int maxSortStrLen;
|
||||||
|
|
||||||
|
public CbmBase(SortEnum[] sortEnums, DataEnum[] dataEnums) {
|
||||||
|
this.sortImplementations = sortEnums;
|
||||||
|
this.dataEnums = dataEnums;
|
||||||
|
|
||||||
|
maxDataEnumStrLen = Arrays.stream(dataEnums).map(e -> e.toString().length()).max(Integer::compareTo).orElse(0);
|
||||||
|
maxSortStrLen = Arrays.stream(sortEnums).map(e -> e.toString().length()).max(Integer::compareTo).orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
for (DataEnum dataEnum : dataEnums) {
|
for (DataEnum dataEnum : dataEnums) {
|
||||||
ObjectSupplier objectSupplier = null;
|
ObjectSupplier objectSupplier = null;
|
||||||
for (SortEnum sortImplementation : sortImplementations) {
|
for (SortEnum sortImplementation : sortImplementations) {
|
||||||
if (!Filter.isFiltered(dataEnum, sortImplementation)) {
|
if (!Filter.isFiltered(dataEnum, sortImplementation)) {
|
||||||
if (objectSupplier == null) {
|
if (objectSupplier == null) {
|
||||||
System.out.println("⏳ Creating object supplier " + dataEnum + " ⏳");
|
System.out.println("Creating object supplier " + dataEnum);
|
||||||
|
System.out.println();
|
||||||
objectSupplier = dataEnum.getObjectSupplier();
|
objectSupplier = dataEnum.getObjectSupplier();
|
||||||
}
|
}
|
||||||
benchmark(objectSupplier, sortImplementation);
|
|
||||||
|
String dataEnumStr = dataEnum.toString();
|
||||||
|
dataEnumStr += " ".repeat(maxDataEnumStrLen - dataEnumStr.length());
|
||||||
|
String sortImplStr = sortImplementation.toString();
|
||||||
|
sortImplStr += " ".repeat(maxSortStrLen - sortImplStr.length());
|
||||||
|
|
||||||
|
CbmBench cbmBench = new CbmBench(dataEnumStr, sortImplStr, objectSupplier, sortImplementation);
|
||||||
|
cbmBench.run();
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println();
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package de.uni_marburg.powersort.benchmark;
|
||||||
|
|
||||||
|
import de.uni_marburg.powersort.data.ObjectSupplier;
|
||||||
|
import de.uni_marburg.powersort.sort.SortEnum;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class CbmBench implements Runnable{
|
||||||
|
private final String dataEnumStr;
|
||||||
|
private final String sortImplStr;
|
||||||
|
private final ObjectSupplier objectSupplier;
|
||||||
|
private final SortEnum sortImplementation;
|
||||||
|
|
||||||
|
public CbmBench(String dataEnumStr, String sortImplStr, ObjectSupplier objectSupplier, SortEnum sortImplementation) {
|
||||||
|
this.dataEnumStr = dataEnumStr;
|
||||||
|
this.sortImplStr = sortImplStr;
|
||||||
|
this.objectSupplier = objectSupplier;
|
||||||
|
this.sortImplementation = sortImplementation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Warmup
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
benchmark(true);
|
||||||
|
}
|
||||||
|
// Measure
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
benchmark(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void benchmark(boolean warmup) {
|
||||||
|
System.out.print(dataEnumStr + "," + sortImplStr + ",");
|
||||||
|
if (warmup) {
|
||||||
|
System.out.print("WARMUP ,");
|
||||||
|
} else {
|
||||||
|
System.out.print("MEASURE,");
|
||||||
|
}
|
||||||
|
System.out.flush();
|
||||||
|
|
||||||
|
Object[] sortInput = objectSupplier.getCopy();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -5,9 +5,10 @@ import de.uni_marburg.powersort.sort.SortEnum;
|
|||||||
|
|
||||||
public class CbmCgl {
|
public class CbmCgl {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
CbmBase.run(
|
CbmBase cbmBase = new CbmBase(
|
||||||
SortEnum.values(),
|
SortEnum.values(),
|
||||||
CglEnum.values()
|
CglEnum.values()
|
||||||
);
|
);
|
||||||
|
cbmBase.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,10 @@ import de.uni_marburg.powersort.sort.SortEnum;
|
|||||||
|
|
||||||
public class CbmCompetition {
|
public class CbmCompetition {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
CbmBase.run(
|
CbmBase cbmBase = new CbmBase(
|
||||||
SortEnum.values(),
|
SortEnum.values(),
|
||||||
CompetitionEnum.values()
|
CompetitionEnum.values()
|
||||||
);
|
);
|
||||||
|
cbmBase.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,6 +128,7 @@ public class Filter {
|
|||||||
return List.of(
|
return List.of(
|
||||||
CglEnum.DESCENDING_INTEGERS,
|
CglEnum.DESCENDING_INTEGERS,
|
||||||
CglEnum.ASCENDING_RUNS,
|
CglEnum.ASCENDING_RUNS,
|
||||||
|
CglEnum.ASCENDING_RUNS_WITH_OVERLAP,
|
||||||
|
|
||||||
CompetitionEnum.COMPETITION_83,
|
CompetitionEnum.COMPETITION_83,
|
||||||
CompetitionEnum.COMPETITION_85,
|
CompetitionEnum.COMPETITION_85,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user