Commit 661214a6 authored by Noric Couderc's avatar Noric Couderc

Optimizations

Relied on streams more instead of lists, trying to get faster running
of generated benchmarks

Removed double-generation of benchmarks
parent 2b33aa2a
......@@ -28,13 +28,14 @@ public class TraceBenchmarkRunner extends SyntheticBenchmarkRunner {
* @return
*/
public List<TrainingSetValue.CollectionSuggestion>
getSuggestions(List<Pair<TraceLoader.TraceData, BCBenchmarkPackage<?>>> l) {
getSuggestions(Stream<Pair<TraceLoader.TraceData, BCBenchmarkPackage<?>>> s) {
Map<String, List<Pair<TraceLoader.TraceData, BCBenchmarkPackage<?>>>>
groups = new TreeMap(
l.stream().collect(Collectors.groupingBy(it -> it.component1().getLocation())));
s.collect(Collectors.groupingBy(it -> it.component1().getLocation())));
ArrayList<TrainingSetValue.CollectionSuggestion> suggestions = new ArrayList<>();
for (Map.Entry<String, List<Pair<TraceLoader.TraceData, BCBenchmarkPackage<?>>>> g : groups.entrySet()) {
System.out.println("Getting suggestion for: " + g.getKey());
// We want the location
String location = g.getKey();
// We want the current type at that location
......
......@@ -20,9 +20,10 @@ class NaiveClassifier(reader : Reader, writer : Writer) {
fun classifyFromReader(tsv : Boolean) {
val loader = TraceLoader()
System.out.println("Generating benchmarks...")
val data = loader.benchmarksFromTraces(reader, tsv = tsv)
val results = TraceBenchmarkRunner().getSuggestions(
data!!.collect(Collectors.toList())).toList()
System.out.println("Generating benchmarks: done.")
val results = TraceBenchmarkRunner().getSuggestions(data!!).toList()
printHeader()
results.forEach {
......
......@@ -95,15 +95,16 @@ class TraceLoader {
return apps.stream()
}
private fun expandBenchmark(b : BCBenchmarkPackage<*>): List<BCBenchmarkPackage<*>>? {
val traceInfo = b.benchmarkIdentifier.split(":")
private fun expandBenchmark(td : TraceData): List<BCBenchmarkPackage<*>>? {
val traceInfo = td.location + ":" + td.object_id
// TODO: There's probably a better way than re-parsing data.
val traceKey = listOf<String>(traceInfo[1], traceInfo[2]).joinToString(":")
return when (b.interfaceIdentifier) {
"List" -> return ListSyntheticBenchmarkGenerator().createApplications(traceKey, b.trace).toList()
"Map" -> return MapSyntheticBenchmarkGenerator().createApplications(traceKey, b.trace).toList()
"Set" -> return SetSyntheticBenchmarkGenerator().createApplications(traceKey, b.trace).toList()
else -> throw RuntimeException("Invalid interface ID: " + b.interfaceIdentifier)
val interfaceName = getClassForName(td.target_type)?.let { getCandidates(it) }
.let { it?.first?.first() }
return when (interfaceName) {
"java.util.List" -> return ListSyntheticBenchmarkGenerator().createApplications(traceInfo, td.methods).toList()
"java.util.Map" -> return MapSyntheticBenchmarkGenerator().createApplications(traceInfo, td.methods).toList()
"java.util.Set" -> return SetSyntheticBenchmarkGenerator().createApplications(traceInfo, td.methods).toList()
else -> throw RuntimeException("Invalid interface ID: $interfaceName")
}
}
......@@ -117,9 +118,9 @@ class TraceLoader {
* @return a stream of benchmarks were each trace has several benchmarks (one for each possible replacement)
*/
fun benchmarksFromTraces(r : Reader, tsv : Boolean) : Stream<Pair<TraceData, BCBenchmarkPackage<*>>>? {
return readCsvWithMetadata(r, tsv).stream().flatMap { p ->
val otherBenchmarks = expandBenchmark(p.second)?.stream()!!
otherBenchmarks.map { Pair(p.first, it) }
return readCsvData(r, tsv).stream().flatMap { p ->
val otherBenchmarks = expandBenchmark(p)?.stream()!!
otherBenchmarks.map { Pair(p, it) }
}
}
......
......@@ -111,7 +111,7 @@ public class SyntheticBenchmarkRunnerTest {
TraceBenchmarkRunner runner = new TraceBenchmarkRunner(10, 10000);
// Benchmarks are too unstable to get a stable suggested value :(
List<TrainingSetValue.CollectionSuggestion> suggestions =
runner.getSuggestions(benchmarks.collect(Collectors.toList()));
runner.getSuggestions(benchmarks);
Assert.assertEquals(3, suggestions.size());
Assert.assertEquals("loc1", suggestions.get(0).getLocation());
......
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