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

added StopWatchTest

parent 0bc285cb
No related branches found
No related tags found
No related merge requests found
......@@ -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,11 +134,13 @@ 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);
if (size > 0) {
System.out.println("SchedulingOverhead: " + TimeUnit.NANOSECONDS.toMillis(schedulingOverheadInNs) + " ms");
System.out.println("avg overhead of iteration: "
+ TimeUnit.NANOSECONDS.toMillis(schedulingOverheadInNs / (size / 2)) + " ms");
+ TimeUnit.NANOSECONDS.toMillis(schedulingOverheadInNs * 2 / size) + " ms");
System.out.println("ExecutedUnsuccessfullyCount: " + this.workerThread.getExecutedUnsuccessfullyCount());
}
}
public int getNumNoopFilters() {
return this.numNoopFilters;
......
......@@ -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();
......
......@@ -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);
......
......@@ -34,7 +34,7 @@ import teetime.util.StopWatch;
*/
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() {
......
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.
Please register or to comment