changeset 328:a020506bbc01

CSV results to follow the guidance from RFC 4180.
author shade
date Thu, 09 Jan 2014 17:33:48 +0400
parents f227bf756864
children ae2f1275697d
files jmh-core/src/main/java/org/openjdk/jmh/output/results/CSVResultFormat.java jmh-core/src/test/resources/org/openjdk/jmh/output/results/output-golden.csv
diffstat 2 files changed, 43 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/output/results/CSVResultFormat.java	Wed Jan 01 18:17:34 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/output/results/CSVResultFormat.java	Thu Jan 09 17:33:48 2014 +0400
@@ -27,12 +27,19 @@
 import org.openjdk.jmh.logic.results.RunResult;
 import org.openjdk.jmh.runner.BenchmarkRecord;
 
+import java.io.BufferedWriter;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Map;
 
 public class CSVResultFormat implements ResultFormat {
 
+    /*
+     * Implementation note:
+     *    We follow the provisions of http://tools.ietf.org/html/rfc4180
+     */
+
     private final String output;
 
     public CSVResultFormat(String output) {
@@ -41,39 +48,46 @@
 
     @Override
     public void writeOut(Map<BenchmarkRecord, RunResult> results) {
-        PrintWriter pw = null;
+        FileWriter fw = null;
         try  {
-            pw = new PrintWriter(output);
+            fw = new FileWriter(output);
+            BufferedWriter bw = new BufferedWriter(fw);
 
-            pw.println("\"Benchmark\", \"Mode\", \"Threads\", \"Iterations\", \"Iteration time\", \"Mean\", \"Mean Error (95%)\", \"Mean Error (99%)\", \"Unit\"");
+            bw.write("\"Benchmark\",\"Mode\",\"Threads\",\"Iterations\",\"Iteration time\",\"Mean\",\"Mean Error (99.9%)\",\"Unit\"");
+            bw.write("\r\n");
 
             for (BenchmarkRecord br : results.keySet()) {
                 RunResult runResult = results.get(br);
 
-                pw.print("\"");
-                pw.print(br.getUsername());
-                pw.print("\", \"");
-                pw.print(br.getMode().shortLabel());
-                pw.print("\", ");
-                pw.print(runResult.getParams().getThreads());
-                pw.print(", ");
-                pw.print(runResult.getParams().getMeasurement().getCount());
-                pw.print(", \"");
-                pw.print(runResult.getParams().getMeasurement().getTime());
-                pw.print("\", ");
-                pw.print(runResult.getPrimaryResult().getStatistics().getMean());
-                pw.print(", ");
-                pw.print(runResult.getPrimaryResult().getStatistics().getMeanErrorAt(0.999));
-                pw.print(", \"");
-                pw.print(runResult.getPrimaryResult().getScoreUnit());
-                pw.println("\"");
+                bw.write("\"");
+                bw.write(br.getUsername());
+                bw.write("\",\"");
+                bw.write(br.getMode().shortLabel());
+                bw.write("\",");
+                bw.write(String.valueOf(runResult.getParams().getThreads()));
+                bw.write(",");
+                bw.write(String.valueOf(runResult.getParams().getMeasurement().getCount()));
+                bw.write(",\"");
+                bw.write(String.valueOf(runResult.getParams().getMeasurement().getTime()));
+                bw.write("\",");
+                bw.write(String.valueOf(runResult.getPrimaryResult().getStatistics().getMean()));
+                bw.write(",");
+                bw.write(String.valueOf(runResult.getPrimaryResult().getStatistics().getMeanErrorAt(0.999)));
+                bw.write(",\"");
+                bw.write(runResult.getPrimaryResult().getScoreUnit());
+                bw.write("\"");
+                bw.write("\r\n");
             }
-
+            bw.close();
         } catch (IOException e) {
             throw new IllegalStateException(e);
         } finally {
-            if (pw != null) {
-                pw.close();
+            if (fw != null) {
+                try {
+                    fw.close();
+                } catch (IOException e) {
+                    // do nothing
+                }
             }
         }
 
--- a/jmh-core/src/test/resources/org/openjdk/jmh/output/results/output-golden.csv	Wed Jan 01 18:17:34 2014 +0400
+++ b/jmh-core/src/test/resources/org/openjdk/jmh/output/results/output-golden.csv	Thu Jan 09 17:33:48 2014 +0400
@@ -1,6 +1,6 @@
-"Benchmark", "Mode", "Threads", "Iterations", "Iteration time", "Mean", "Mean Error (95%)", "Mean Error (99%)", "Unit"
-"benchmark_0", "avgt", 80, 802, "501 s", 528.8571428571429, 253.83689091986184, "ops/ms"
-"benchmark_1", "avgt", 900, 55, "398 s", 439.0, NaN, "ops/ms"
-"benchmark_2", "avgt", 466, 461, "96 s", 545.0, 493.81293072112726, "ops/ms"
-"benchmark_3", "avgt", 968, 857, "438 s", 417.57142857142856, 331.1099544524174, "ops/ms"
-"benchmark_4", "avgt", 739, 16, "763 s", 956.0, NaN, "ops/ms"
+"Benchmark","Mode","Threads","Iterations","Iteration time","Mean","Mean Error (99.9%)","Unit"
+"benchmark_0","avgt",80,802,"501 s",528.8571428571429,253.83689091986184,"ops/ms"
+"benchmark_1","avgt",900,55,"398 s",439.0,NaN,"ops/ms"
+"benchmark_2","avgt",466,461,"96 s",545.0,493.81293072112726,"ops/ms"
+"benchmark_3","avgt",968,857,"438 s",417.57142857142856,331.1099544524174,"ops/ms"
+"benchmark_4","avgt",739,16,"763 s",956.0,NaN,"ops/ms"