Skip to content
Snippets Groups Projects
Commit 6f2bbaa6 authored by Nikolaus Krismer's avatar Nikolaus Krismer
Browse files

added csv file generation (for easy plotting of runtimes)

parent 57344019
No related branches found
No related tags found
No related merge requests found
package it.unibz.inf.isochrone.network; package it.unibz.inf.isochrone.network;
import com.google.common.base.Charsets;
import it.unibz.inf.isochrone.algorithm.Isochrone; import it.unibz.inf.isochrone.algorithm.Isochrone;
import it.unibz.inf.isochrone.algorithm.MDijkstra; import it.unibz.inf.isochrone.algorithm.MDijkstra;
import it.unibz.inf.isochrone.algorithm.MineX; import it.unibz.inf.isochrone.algorithm.MineX;
...@@ -38,6 +40,8 @@ import org.testng.annotations.Test; ...@@ -38,6 +40,8 @@ import org.testng.annotations.Test;
public final class AlgorithmRuntimeTest { public final class AlgorithmRuntimeTest {
private static final Logger LOGGER = LoggerFactory.getLogger(AlgorithmRuntimeTest.class); private static final Logger LOGGER = LoggerFactory.getLogger(AlgorithmRuntimeTest.class);
private static final int REPEAT_COUNT = 5; private static final int REPEAT_COUNT = 5;
private static final String RESULTFILE_ENCODING = Charsets.UTF_8.toString();
private static final String RESULTFILE_CSV_RUNTIME = "build/reports/tests/algorithm-runtimes.csv";
private static final String RESULTFILE_XML_RUNTIME = "build/reports/tests/algorithm-runtimes.xml"; private static final String RESULTFILE_XML_RUNTIME = "build/reports/tests/algorithm-runtimes.xml";
private static final Direction DIRECTION = Direction.INCOMING; private static final Direction DIRECTION = Direction.INCOMING;
private static final Mode MODE = Mode.MULTIMODAL; private static final Mode MODE = Mode.MULTIMODAL;
...@@ -106,9 +110,9 @@ public final class AlgorithmRuntimeTest { ...@@ -106,9 +110,9 @@ public final class AlgorithmRuntimeTest {
// Public static methods // Public static methods
@AfterClass @AfterClass
public static void writeRuntimeXML() { public static void writeRuntimes() {
final Set<Entry<String, Map<String, Long>>> resultSet = runtimes.entrySet(); writeRuntimeXML();
writeMapToXML(new File(RESULTFILE_XML_RUNTIME), resultSet, REPEAT_COUNT); writeRuntimeCSV();
} }
@BeforeClass @BeforeClass
...@@ -211,7 +215,7 @@ public final class AlgorithmRuntimeTest { ...@@ -211,7 +215,7 @@ public final class AlgorithmRuntimeTest {
private static void addRuntimeEntry(final String time, final String algorithm, final long runtime) { private static void addRuntimeEntry(final String time, final String algorithm, final long runtime) {
if (!runtimes.containsKey(time)) { if (!runtimes.containsKey(time)) {
runtimes.put(time, new HashMap<String, Long>()); runtimes.put(time, new LinkedHashMap<String, Long>());
} }
final Map<String, Long> algorithmMap = runtimes.get(time); final Map<String, Long> algorithmMap = runtimes.get(time);
...@@ -223,11 +227,50 @@ public final class AlgorithmRuntimeTest { ...@@ -223,11 +227,50 @@ public final class AlgorithmRuntimeTest {
} }
} }
private static void writeMapToCSV(final File file, final Set<Entry<String, Map<String, Long>>> resultSet, final int repeatCount) {
BufferedWriter fw = null;
try {
fw = new BufferedWriter(new PrintWriter(file, RESULTFILE_ENCODING));
boolean isFirstLine = true;
for (Entry<String, Map<String, Long>> runtimeEntry : resultSet) {
final String time = runtimeEntry.getKey();
final Map<String, Long> results = runtimeEntry.getValue();
if (isFirstLine) {
fw.write("Runtime;");
final Set<String> algorithms = results.keySet();
for (String algorithmName : algorithms) {
fw.write(algorithmName + ";");
}
fw.newLine();
isFirstLine = false;
}
fw.write(time + ";");
final Set<Entry<String, Long>> timeSet = results.entrySet();
for (Entry<String, Long> entry : timeSet) {
fw.write((entry.getValue().longValue() / repeatCount) + ";");
}
fw.newLine();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fw != null) {
try {
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static void writeMapToXML(final File file, final Set<Entry<String, Map<String, Long>>> resultSet, final int repeatCount) { private static void writeMapToXML(final File file, final Set<Entry<String, Map<String, Long>>> resultSet, final int repeatCount) {
BufferedWriter fw = null; BufferedWriter fw = null;
try { try {
fw = new BufferedWriter(new PrintWriter(file, "UTF-8")); fw = new BufferedWriter(new PrintWriter(file, RESULTFILE_ENCODING));
fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); fw.write("<?xml version=\"1.0\" encoding=\"" + RESULTFILE_ENCODING + "\"?>");
fw.newLine(); fw.newLine();
fw.write("<results numberOfRuns=\"" + repeatCount + "\">"); fw.write("<results numberOfRuns=\"" + repeatCount + "\">");
fw.newLine(); fw.newLine();
...@@ -262,4 +305,14 @@ public final class AlgorithmRuntimeTest { ...@@ -262,4 +305,14 @@ public final class AlgorithmRuntimeTest {
} }
} }
private static void writeRuntimeCSV() {
final Set<Entry<String, Map<String, Long>>> resultSet = runtimes.entrySet();
writeMapToCSV(new File(RESULTFILE_CSV_RUNTIME), resultSet, REPEAT_COUNT);
}
private static void writeRuntimeXML() {
final Set<Entry<String, Map<String, Long>>> resultSet = runtimes.entrySet();
writeMapToXML(new File(RESULTFILE_XML_RUNTIME), resultSet, REPEAT_COUNT);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment