mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
try to stabilize performance test timings even more
This commit is contained in:
@@ -23,7 +23,6 @@ import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
/**
|
||||
@@ -33,9 +32,11 @@ public class CpuTimings {
|
||||
final long[] rawData;
|
||||
long average;
|
||||
private final double myStandardDeviation;
|
||||
private final int attempt;
|
||||
|
||||
private CpuTimings(long[] rawData) {
|
||||
private CpuTimings(long[] rawData, int attempt) {
|
||||
this.rawData = rawData;
|
||||
this.attempt = attempt;
|
||||
average = ArrayUtil.averageAmongMedians(rawData, 2);
|
||||
myStandardDeviation = standardDeviation(rawData);
|
||||
}
|
||||
@@ -52,14 +53,14 @@ public class CpuTimings {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CpuTimings{" + average + ", raw=" + Arrays.toString(rawData) + ", sd=" + myStandardDeviation + '}';
|
||||
return average + "[sd=" + myStandardDeviation + ", attempt=" + attempt + "]";
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
static CpuTimings calcStableCpuTiming() {
|
||||
int maxIterations = UsefulTestCase.IS_UNDER_TEAMCITY ? 100 : 10;
|
||||
for (int i = 0;; i++) {
|
||||
CpuTimings timings = calcCpuTiming(20, CpuTimings::addBigIntegers);
|
||||
CpuTimings timings = calcCpuTiming(20, CpuTimings::addBigIntegers, i);
|
||||
if (timings.myStandardDeviation < 1.8) {
|
||||
return timings;
|
||||
}
|
||||
@@ -71,17 +72,18 @@ public class CpuTimings {
|
||||
System.out.println(i + ": Unstable timings: " + timings+" (getProcessCpuLoad() = " + getProcessCpuLoad()+"; getSystemCpuLoad() = " + getSystemCpuLoad()+")");
|
||||
}
|
||||
System.gc();
|
||||
PlatformTestUtil.waitForAllBackgroundActivityToCalmDown();
|
||||
}
|
||||
}
|
||||
|
||||
private static CpuTimings calcCpuTiming(int iterationCount, Runnable oneIteration) {
|
||||
private static CpuTimings calcCpuTiming(int iterationCount, Runnable oneIteration, int attempt) {
|
||||
long[] elapsed = new long[iterationCount];
|
||||
for (int i = 0; i < iterationCount; i++) {
|
||||
long start = System.currentTimeMillis();
|
||||
oneIteration.run();
|
||||
elapsed[i] = System.currentTimeMillis() - start;
|
||||
}
|
||||
return new CpuTimings(elapsed);
|
||||
return new CpuTimings(elapsed, attempt);
|
||||
}
|
||||
|
||||
private static void addBigIntegers() {
|
||||
|
||||
@@ -680,7 +680,7 @@ public class PlatformTestUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForAllBackgroundActivityToCalmDown() {
|
||||
static void waitForAllBackgroundActivityToCalmDown() {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
CpuUsageData data = CpuUsageData.measureCpuUsage(() -> TimeoutUtil.sleep(100));
|
||||
if (!data.hasAnyActivityBesides(Thread.currentThread())) {
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Timings {
|
||||
private static final int IO_PROBES = 42;
|
||||
|
||||
public static final long CPU_TIMING;
|
||||
private static final CpuTimings CPU_TIMING_DATA;
|
||||
public static final long IO_TIMING;
|
||||
|
||||
/**
|
||||
@@ -37,8 +38,8 @@ public class Timings {
|
||||
public static final long REFERENCE_IO_TIMING = 100;
|
||||
|
||||
static {
|
||||
CpuTimings timings = CpuTimings.calcStableCpuTiming();
|
||||
CPU_TIMING = timings.average;
|
||||
CPU_TIMING_DATA = CpuTimings.calcStableCpuTiming();
|
||||
CPU_TIMING = CPU_TIMING_DATA.average;
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < IO_PROBES; i++) {
|
||||
@@ -96,7 +97,7 @@ public class Timings {
|
||||
|
||||
public static String getStatistics() {
|
||||
return
|
||||
" Timings: CPU=" + CPU_TIMING + " (" + (int)(CPU_TIMING * 1.0 / REFERENCE_CPU_TIMING * 100) + "% of the reference CPU)" +
|
||||
" Timings: CPU=" + CPU_TIMING_DATA + " (" + (int)(CPU_TIMING * 1.0 / REFERENCE_CPU_TIMING * 100) + "% of the reference CPU)" +
|
||||
", I/O=" + IO_TIMING + " (" + (int)(IO_TIMING * 1.0 / REFERENCE_IO_TIMING * 100) + "% of the reference IO)" +
|
||||
", " + Runtime.getRuntime().availableProcessors() + " cores.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user