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

added StopWatchTest

parent 88df3d7b
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@ import teetime.stage.basic.ObjectProducer;
/**
* @author Christian Wulf
*
*
* @since 1.10
*/
public class ThroughputTimestampAnalysis extends Analysis {
......@@ -74,7 +74,8 @@ public class ThroughputTimestampAnalysis extends Analysis {
@SuppressWarnings("unchecked")
final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[numNoopFilters];
// create stages
final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator);
final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(
this.numInputObjects, this.inputObjectCreator);
final StartTimestampFilter startTimestampFilter = new StartTimestampFilter();
for (int i = 0; i < noopFilters.length; i++) {
noopFilters[i] = new NoopFilter<TimestampObject>();
......@@ -133,10 +134,12 @@ public class ThroughputTimestampAnalysis extends Analysis {
final long schedulingOverheadInNs = this.workerThread.computeSchedulingOverheadInNs();
final int size = this.workerThread.getSchedulingOverheadsInNs().size();
System.out.println("scheduling overhead times: " + size);
System.out.println("SchedulingOverhead: " + TimeUnit.NANOSECONDS.toMillis(schedulingOverheadInNs) + " ms");
System.out.println("avg overhead of iteration: "
+ TimeUnit.NANOSECONDS.toMillis(schedulingOverheadInNs / (size / 2)) + " ms");
System.out.println("ExecutedUnsuccessfullyCount: " + this.workerThread.getExecutedUnsuccessfullyCount());
if (size > 0) {
System.out.println("SchedulingOverhead: " + TimeUnit.NANOSECONDS.toMillis(schedulingOverheadInNs) + " ms");
System.out.println("avg overhead of iteration: "
+ TimeUnit.NANOSECONDS.toMillis(schedulingOverheadInNs * 2 / size) + " ms");
System.out.println("ExecutedUnsuccessfullyCount: " + this.workerThread.getExecutedUnsuccessfullyCount());
}
}
public int getNumNoopFilters() {
......
......@@ -25,7 +25,7 @@ import teetime.util.StopWatch;
/**
* @author Christian Wulf
*
*
* @since 1.10
*/
public class WorkerThread extends Thread {
......@@ -64,7 +64,7 @@ public class WorkerThread extends Thread {
while (this.stageScheduler.isAnyStageActive()) {
iterations++;
this.iterationStopWatch.start();
// this.iterationStopWatch.start();
final IStage stage = this.stageScheduler.get();
......@@ -77,13 +77,13 @@ public class WorkerThread extends Thread {
}
this.stageScheduler.determineNextStage(stage, executedSuccessfully);
this.iterationStopWatch.end();
final long schedulingOverhead = this.iterationStopWatch.getDurationInNs() - stage.getLastDuration();
schedulingOverheadInNs += schedulingOverhead;
if ((iterations % 10000) == 0) {
this.schedulingOverheadsInNs.add(schedulingOverheadInNs);
schedulingOverheadInNs = 0;
}
// this.iterationStopWatch.end();
// final long schedulingOverhead = this.iterationStopWatch.getDurationInNs() - stage.getLastDuration();
// schedulingOverheadInNs += schedulingOverhead;
// if ((iterations % 10000) == 0) {
// this.schedulingOverheadsInNs.add(schedulingOverheadInNs);
// schedulingOverheadInNs = 0;
// }
}
this.stopWatch.end();
......@@ -165,7 +165,7 @@ public class WorkerThread extends Thread {
/**
* If not set, this thread will run infinitely.
*
*
* @param terminationPolicyToUse
*/
public void setTerminationPolicy(final StageTerminationPolicy terminationPolicyToUse) {
......@@ -190,7 +190,7 @@ public class WorkerThread extends Thread {
/**
* Uses the last half of values to compute the scheduling overall overhead in ns
*
*
* @since 1.10
*/
public long computeSchedulingOverheadInNs() {
......
......@@ -67,9 +67,7 @@ public class StatisticsUtil {
final long avgDurInNs = sumInNs / (timestampObjects.size() / 2);
System.out.println("avg duration: " + TimeUnit.NANOSECONDS.toMicros(avgDurInNs) + " µs");
for (final Entry<Double, Long> entry : quintileValues.entrySet()) {
System.out.println((entry.getKey() * 100) + " % : " + TimeUnit.NANOSECONDS.toMicros(entry.getValue()) + " µs");
}
printQuintiles(quintileValues);
final long confidenceWidthInNs = StatisticsUtil.calculateConfidenceWidth(sortedDurationsInNs, avgDurInNs);
......@@ -78,6 +76,12 @@ public class StatisticsUtil {
+ TimeUnit.NANOSECONDS.toMicros(avgDurInNs + confidenceWidthInNs) + " µs]");
}
public static void printQuintiles(final Map<Double, Long> quintileValues) {
for (final Entry<Double, Long> entry : quintileValues.entrySet()) {
System.out.println((entry.getKey() * 100) + " % : " + TimeUnit.NANOSECONDS.toMicros(entry.getValue()) + " µs");
}
}
public static long calculateConfidenceWidth(final List<Long> durations, final long avgDurInNs) {
final double z = 1.96; // for alpha = 0.05
final double variance = MathUtil.getVariance(durations, avgDurInNs);
......
......@@ -29,12 +29,12 @@ import teetime.util.StopWatch;
/**
* @author Christian Wulf
*
*
* @since 1.10
*/
public class ThroughputTimestampAnalysisTest {
private static final int NUM_OBJECTS_TO_CREATE = 100000;
private static final int NUM_OBJECTS_TO_CREATE = 50000;
@Before
public void before() {
......@@ -49,7 +49,7 @@ public class ThroughputTimestampAnalysisTest {
* <li>SchedulingOverhead: 12629 ms
* <li>ExecutedUnsuccessfullyCount: 80300001
* </ul>
*
*
* QueuePipes:
* <ul>
* <li>SchedulingOverhead: 11337 ms
......
package teetime.util;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
public class StopWatchTest {
private static final int NUM_ITERATIONS = 1000000;
@Test
public void testNanotime() throws Exception {
StopWatch iterationStopWatch = new StopWatch();
List<Long> durationsInNs = new ArrayList<Long>(NUM_ITERATIONS);
for (int i = 0; i < NUM_ITERATIONS; i++) {
iterationStopWatch.start();
fib(BigInteger.valueOf(10l));
iterationStopWatch.end();
durationsInNs.add(iterationStopWatch.getDurationInNs());
}
Map<Double, Long> quintiles = StatisticsUtil.calculateQuintiles(durationsInNs);
StatisticsUtil.printQuintiles(quintiles);
}
public static BigInteger fib(final BigInteger n) {
if (n.compareTo(BigInteger.ONE) == -1 || n.compareTo(BigInteger.ONE) == 0) {
return n;
} else {
return fib(n.subtract(BigInteger.ONE)).add(fib(n.subtract(BigInteger.ONE).subtract(BigInteger.ONE)));
}
}
}
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