Rewrote to discard first 1000 draw calls due to JVM warmup.
@@ -11,10 +11,8 @@ import java.awt.Color;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
-import java.util.stream.Collectors;
public class SampleDrawTime {
public static void main(final String[] args) throws IOException, URISyntaxException, InterruptedException {
@@ -51,6 +49,8 @@ public class SampleDrawTime {
final long timeAfterDraw = System.nanoTime();
final long timeDifference = timeAfterDraw - timeBeforeDraw;
+
+ if (i > 1000) {
measurements.add(timeDifference);
if (i % 50 == 0) {
@@ -65,17 +65,14 @@ public class SampleDrawTime {
panel.getImageCache().totalCachedImages())
);
}
+ } else {
+ System.out.println("Ignoring first " + i + "/1000 draw calls.");
+ }
Thread.sleep(16);
}
// Remove the bottom and top 10% (outliers) of results:
- Collections.sort(measurements);
- final long middleElement = measurements.get(measurements.size() / 2);
- final double lowestElement = middleElement * 0.80;
- final double highestElement = middleElement + (middleElement * 0.80);
-
- measurements = measurements.stream().filter(val -> val >= lowestElement && val <= highestElement).collect(Collectors.toList());
double averageDrawTime = measurements.stream().mapToLong(Long::longValue).sum() / (double) measurements.size();
averageDrawTime /= 1_000_000;
