Commit 65bb2fa5 authored by Noric Couderc's avatar Noric Couderc

Added method for post processing of benchmarks results

We are only interested in which data structure was the best for a given seed, so
we only keep the name of the data structure that gave the maximum throughput.
parent a227c3ff
package se.lth.cs.jmh;
import com.google.gson.Gson;
import org.openjdk.jmh.results.BenchmarkResult;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
......@@ -7,13 +10,54 @@ import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* Main function to run the jmh benchmakrs and store the results
*/
public class Main {
public static String getResultKey(RunResult r) {
return String.format("%s,%s,%s",
r.getParams().getParam("seed"),
r.getParams().getParam("applicationSize"),
r.getParams().getParam("baseStructureSize"));
}
public static void process(Collection<RunResult> results) {
// We group the results by seed
Map<String, List<RunResult>> resultsBySeed =
results.stream().collect(
Collectors.groupingBy(it -> it.getParams().getParam("seed"))
);
Map<Integer, String> seedsToDatastructure = new HashMap<>();
for (String seed : resultsBySeed.keySet()) {
List<RunResult> rs = resultsBySeed.get(seed);
// We get the application with the best score
Optional<RunResult> best = rs.stream().max(
Comparator.comparing(it -> it.getAggregatedResult().getPrimaryResult().getScore())
);
if (best.isPresent()) {
seedsToDatastructure.put(Integer.parseInt(seed),
best.get().getParams().getParam("datastructureName"));
} else {
seedsToDatastructure.put(Integer.parseInt(seed),
"unknown");
}
}
System.out.println(new Gson().toJson(seedsToDatastructure));
}
public static void main(String[] args) throws RunnerException {
System.out.println("Running the custom jmh runner.");
String[] seedsText = new String[10];
for (int i = 0; i < 10; ++i)
// Preparing seeds
int number_seeds = 2;
String[] seedsText = new String[number_seeds];
for (int i = 0; i < number_seeds; ++i)
seedsText[i] = String.format("%d", i);
Options opts = new OptionsBuilder()
......@@ -24,11 +68,14 @@ public class Main {
.measurementTime(TimeValue.milliseconds(500))
.measurementIterations(5)
.resultFormat(ResultFormatType.CSV)
.result("jmh-results-runner.csv")
//.result("jmh-results-runner.csv")
.param("seed", seedsText)
.param("baseStructureSize", "0")
.param("applicationSize", "400")
.build();
Runner r = new Runner(opts);
r.run();
Collection<RunResult> results = r.run();
process(results);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment