From 88c71bb962d3de098dead53bf50c84f9b6b8364d Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Wed, 14 Sep 2011 15:56:08 +0000 Subject: [PATCH] Enhanced formatting of the results printed to stdout. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1170697 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math/PerfTestUtils.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/math/PerfTestUtils.java b/src/test/java/org/apache/commons/math/PerfTestUtils.java index b1fac6155..6257eb497 100644 --- a/src/test/java/org/apache/commons/math/PerfTestUtils.java +++ b/src/test/java/org/apache/commons/math/PerfTestUtils.java @@ -163,24 +163,49 @@ public class PerfTestUtils { boolean runGC, RunTest ... methods) { // Header format. - final String hFormat = "%s (calls per timed block: %d, timed blocks: %d)"; + final String hFormat = "%s (calls per timed block: %d, timed blocks: %d, time unit: ms)"; + + // Width of the longest name. + int nameLength = 0; + for (RunTest m : methods) { + int len = m.getName().length(); + if (len > nameLength) { + nameLength = len; + } + } + final String nameLengthFormat = "%" + nameLength + "s"; + + // Column format. + final String cFormat = nameLengthFormat + " %14s %14s %10s %10s %15s"; // Result format. - final String format = "%15s: %e (%e) ms"; + final String format = nameLengthFormat + " %.8e %.8e %.4e %.4e % .8e"; System.out.println(String.format(hFormat, title, repeatChunk, repeatStat)); + System.out.println(String.format(cFormat, + "name", + "time/call", + "std error", + "total time", + "ratio", + "difference")); final StatisticalSummary[] time = time(repeatChunk, repeatStat, runGC, methods); + final double refSum = time[0].getSum(); for (int i = 0, max = time.length; i < max; i++) { final StatisticalSummary s = time[i]; + final double sum = s.getSum(); System.out.println(String.format(format, methods[i].getName(), s.getMean(), - s.getStandardDeviation())); + s.getStandardDeviation(), + sum, + sum / refSum, + sum - refSum)); } return time;