comp.writeResults();
}
private void writeResults() {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
StringBuffer res = new StringBuffer("<document>\n" + "<properties>\n" + "<title>Performance comparison with HashMap</title>\n" + "</properties>\n"
+ "<body>" +
"<section name=\"Test harness\"><p>All tests will be successfull " +
"50% of the time, the other 50% will not be successfull, since the" +
"Maps is pre-initialized for each test with keys/values 0-500, and the tests are runned with" +
"keys/values 0-1000." +
"The keys are Strings, while the values are integers.</p></section>" +
"<section name=\"Performance metrics\">\n"
+ "<p>This page presents the results of executing a performance test of FKache versus java.util.HashMap.\n");
res.append("The tests was performed on "+ DateFormat.getDateTimeInstance().format(new Date())+".\n");
res.append("The tests was runned on "+System.getProperty("java.runtime.name") +
" version " + System.getProperty("java.vm.version") +
" by " + System.getProperty("java.vm.vendor")+".\n");
res.append("The operating system was "+ System.getProperty("os.name")+".\n");
res.append("The amount of available memory to the VM was " + Runtime.getRuntime().maxMemory()/1024/1024 + "Mb.\n");
if(!results.isEmpty()) {
res.append("<table><tr><th>method</th><th>Number of repeats</th><th>HashMap</th><th>FKache</th></tr>\n");
Iterator iter = results.keySet().iterator();
while(iter.hasNext()) {
String method = (String) iter.next();
float[] fs = (float[]) results.get(method);
res.append("<tr><td>"+method+"</td><td>"+countFormat.format((long)fs[0]*1000)+"</td><td>"+100*fs[1]+"%</td><td>"+(long)(100F*fs[2])+"%</td></tr>\n");
}
res.append("</table>");
}
res.append("</p>\n</section>\n</body>\n</document>");
writer.write(res.toString());
writer.close();
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("The results could not be written.");
}
}