Differential D1850 Diff 6225 java/server/src/main/java/org/softwareheritage/graph/benchmark/Common.java
Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/main/java/org/softwareheritage/graph/benchmark/Common.java
Show All 17 Lines | |||||
public class Common { | public class Common { | ||||
/** | /** | ||||
* Times a specific endpoint and prints aggregated statistics. | * Times a specific endpoint and prints aggregated statistics. | ||||
* | * | ||||
* @param graph compressed graph used in the benchmark | * @param graph compressed graph used in the benchmark | ||||
* @param nodeIds node ids to use as starting point for the endpoint traversal | * @param nodeIds node ids to use as starting point for the endpoint traversal | ||||
* @param operation endpoint function to benchmark | * @param operation endpoint function to benchmark | ||||
* @param dstFmt destination formatted string as described in the <a | |||||
* href="https://docs.softwareheritage.org/devel/swh-graph/api.html#walk">API</a> | |||||
* @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") | |||||
*/ | */ | ||||
public static void timeEndpoint( | public static void timeEndpoint(Graph graph, long[] nodeIds, | ||||
Graph graph, long[] nodeIds, Function<SwhPID, Endpoint.Output> operation) { | Function<Endpoint.Input, Endpoint.Output> operation, String dstFmt, String algorithm) { | ||||
ArrayList<Double> timings = new ArrayList<>(); | ArrayList<Double> timings = new ArrayList<>(); | ||||
ArrayList<Double> timingsNormalized = new ArrayList<>(); | ArrayList<Double> timingsNormalized = new ArrayList<>(); | ||||
for (long nodeId : nodeIds) { | for (long nodeId : nodeIds) { | ||||
SwhPID swhPID = graph.getSwhPID(nodeId); | SwhPID swhPID = graph.getSwhPID(nodeId); | ||||
Endpoint.Output output = operation.apply(swhPID); | Endpoint.Output output = (dstFmt == null) | ||||
? operation.apply(new Endpoint.Input(swhPID)) | |||||
: operation.apply(new Endpoint.Input(swhPID, dstFmt, algorithm)); | |||||
timings.add(output.meta.timings.traversal); | timings.add(output.meta.timings.traversal); | ||||
if (output.meta.nbEdgesAccessed != 0) { | if (output.meta.nbEdgesAccessed != 0) { | ||||
timingsNormalized.add(output.meta.timings.traversal / output.meta.nbEdgesAccessed); | timingsNormalized.add(output.meta.timings.traversal / output.meta.nbEdgesAccessed); | ||||
} | } | ||||
} | } | ||||
System.out.println("timings:"); | System.out.println("timings:"); | ||||
Statistics stats = new Statistics(timings); | Statistics stats = new Statistics(timings); | ||||
stats.printAll(); | stats.printAll(); | ||||
System.out.println("timings normalized:"); | System.out.println("timings normalized:"); | ||||
Statistics statsNormalized = new Statistics(timingsNormalized); | Statistics statsNormalized = new Statistics(timingsNormalized); | ||||
statsNormalized.printAll(); | statsNormalized.printAll(); | ||||
} | } | ||||
/** | |||||
* Same as {@link timeEndpoint} but without destination or algorithm specified to endpoint call. | |||||
*/ | |||||
public static void timeEndpoint( | |||||
Graph graph, long[] nodeIds, Function<Endpoint.Input, Endpoint.Output> operation) { | |||||
timeEndpoint(graph, nodeIds, operation, null, null); | |||||
} | |||||
} | } |