Skip to content
Snippets Groups Projects
Commit 8a601deb authored by Christian Wulf's avatar Christian Wulf
Browse files

refactored: StatisticsUtil does not print to sysout anymore

parent cb643b9c
No related branches found
No related tags found
No related merge requests found
...@@ -40,11 +40,10 @@ public class StatisticsUtil { ...@@ -40,11 +40,10 @@ public class StatisticsUtil {
// utility class // utility class
} }
public static PerformanceResult printStatistics(final long overallDurationInNs, final List<TimestampObject> timestampObjects) { public static PerformanceResult computeStatistics(final long overallDurationInNs, final List<TimestampObject> timestampObjects) {
PerformanceResult performanceResult = new PerformanceResult(); PerformanceResult performanceResult = new PerformanceResult();
performanceResult.overallDurationInNs = overallDurationInNs; performanceResult.overallDurationInNs = overallDurationInNs;
System.out.println("Duration: " + TimeUnit.NANOSECONDS.toMillis(overallDurationInNs) + " ms");
final List<Long> sortedDurationsInNs = new ArrayList<Long>(timestampObjects.size() / 2); final List<Long> sortedDurationsInNs = new ArrayList<Long>(timestampObjects.size() / 2);
long sumInNs = 0; long sumInNs = 0;
...@@ -59,24 +58,14 @@ public class StatisticsUtil { ...@@ -59,24 +58,14 @@ public class StatisticsUtil {
performanceResult.sumInNs = sumInNs; performanceResult.sumInNs = sumInNs;
final Map<Double, Long> quintileValues = StatisticsUtil.calculateQuintiles(sortedDurationsInNs); final Map<Double, Long> quintileValues = StatisticsUtil.calculateQuintiles(sortedDurationsInNs);
performanceResult.quantiles = quintileValues; performanceResult.quantiles = quintileValues;
final long avgDurInNs = sumInNs / (timestampObjects.size() / 2); final long avgDurInNs = sumInNs / (timestampObjects.size() / 2);
System.out.println("avg duration: " + TimeUnit.NANOSECONDS.toMicros(avgDurInNs) + " µs");
performanceResult.avgDurInNs = avgDurInNs; performanceResult.avgDurInNs = avgDurInNs;
System.out.println(getQuantilesString(quintileValues));
final long confidenceWidthInNs = StatisticsUtil.calculateConfidenceWidth(sortedDurationsInNs, avgDurInNs); final long confidenceWidthInNs = StatisticsUtil.calculateConfidenceWidth(sortedDurationsInNs, avgDurInNs);
performanceResult.confidenceWidthInNs = confidenceWidthInNs; performanceResult.confidenceWidthInNs = confidenceWidthInNs;
System.out.println("confidenceWidth: " + confidenceWidthInNs + " ns");
System.out.println("[" + TimeUnit.NANOSECONDS.toMicros(avgDurInNs - confidenceWidthInNs) + " µs, "
+ TimeUnit.NANOSECONDS.toMicros(avgDurInNs + confidenceWidthInNs) + " µs]");
return performanceResult; return performanceResult;
} }
......
...@@ -61,7 +61,7 @@ public class ThroughputTimestampAnalysisTest extends PerformanceTest { ...@@ -61,7 +61,7 @@ public class ThroughputTimestampAnalysisTest extends PerformanceTest {
stopWatch.end(); stopWatch.end();
} }
StatisticsUtil.printStatistics(stopWatch.getDurationInNs(), timestampObjects); StatisticsUtil.computeStatistics(stopWatch.getDurationInNs(), timestampObjects);
} }
} }
...@@ -58,7 +58,7 @@ public class ThroughputTimestampAnalysisTest extends PerformanceTest { ...@@ -58,7 +58,7 @@ public class ThroughputTimestampAnalysisTest extends PerformanceTest {
stopWatch.end(); stopWatch.end();
} }
StatisticsUtil.printStatistics(stopWatch.getDurationInNs(), timestampObjects); StatisticsUtil.computeStatistics(stopWatch.getDurationInNs(), timestampObjects);
} }
} }
...@@ -15,10 +15,14 @@ ...@@ -15,10 +15,14 @@
***************************************************************************/ ***************************************************************************/
package teetime.variant.methodcall.examples.experiment01; package teetime.variant.methodcall.examples.experiment01;
import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import teetime.util.ConstructorClosure; import teetime.util.ConstructorClosure;
import teetime.util.StatisticsUtil;
import teetime.variant.explicitScheduling.examples.throughput.TimestampObject; import teetime.variant.explicitScheduling.examples.throughput.TimestampObject;
import test.PerformanceResult;
import test.PerformanceTest; import test.PerformanceTest;
/** /**
...@@ -28,8 +32,7 @@ import test.PerformanceTest; ...@@ -28,8 +32,7 @@ import test.PerformanceTest;
*/ */
public class MethodCallThoughputTimestampAnalysis1Test extends PerformanceTest { public class MethodCallThoughputTimestampAnalysis1Test extends PerformanceTest {
// 500 times faster than our new framework // TODO check why the optimal, but inflexible impl is 500 times faster than our new framework
// TODO check why
@Test @Test
public void testWithManyObjects() { public void testWithManyObjects() {
...@@ -54,6 +57,8 @@ public class MethodCallThoughputTimestampAnalysis1Test extends PerformanceTest { ...@@ -54,6 +57,8 @@ public class MethodCallThoughputTimestampAnalysis1Test extends PerformanceTest {
this.stopWatch.end(); this.stopWatch.end();
} }
PerformanceResult performanceResult = StatisticsUtil.computeStatistics(this.stopWatch.getDurationInNs(), this.timestampObjects);
assertEquals(292, performanceResult.quantiles.get(0.5), 1); // chw home
} }
} }
...@@ -2,6 +2,7 @@ package test; ...@@ -2,6 +2,7 @@ package test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
...@@ -23,7 +24,7 @@ public abstract class PerformanceTest { ...@@ -23,7 +24,7 @@ public abstract class PerformanceTest {
public static final MeasurementRepository measurementRepository = new MeasurementRepository(); public static final MeasurementRepository measurementRepository = new MeasurementRepository();
private Description description; protected Description description;
protected StopWatch stopWatch; protected StopWatch stopWatch;
protected List<TimestampObject> timestampObjects; protected List<TimestampObject> timestampObjects;
...@@ -46,7 +47,14 @@ public abstract class PerformanceTest { ...@@ -46,7 +47,14 @@ public abstract class PerformanceTest {
@After @After
public void after() { public void after() {
PerformanceResult performanceResult = StatisticsUtil.printStatistics(this.stopWatch.getDurationInNs(), this.timestampObjects); PerformanceResult performanceResult = StatisticsUtil.computeStatistics(this.stopWatch.getDurationInNs(), this.timestampObjects);
measurementRepository.performanceResults.put(this.description.getDisplayName(), performanceResult); measurementRepository.performanceResults.put(this.description.getDisplayName(), performanceResult);
System.out.println("Duration: " + TimeUnit.NANOSECONDS.toMillis(performanceResult.overallDurationInNs) + " ms");
System.out.println("avg duration: " + TimeUnit.NANOSECONDS.toMicros(performanceResult.avgDurInNs) + " µs");
System.out.println(StatisticsUtil.getQuantilesString(performanceResult.quantiles));
System.out.println("confidenceWidth: " + performanceResult.confidenceWidthInNs + " ns");
System.out.println("[" + TimeUnit.NANOSECONDS.toMicros(performanceResult.avgDurInNs - performanceResult.confidenceWidthInNs) + " µs, "
+ TimeUnit.NANOSECONDS.toMicros(performanceResult.avgDurInNs + performanceResult.confidenceWidthInNs) + " µs]");
} }
} }
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