diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java index 0c14e4acdf2b..c54345cf5cab 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightStressTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ import com.intellij.psi.*; import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiShortNamesCache; -import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.SkipSlowTestLocally; +import com.intellij.util.ArrayUtil; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; @@ -129,7 +129,7 @@ public class HighlightStressTest extends LightDaemonAnalyzerTestCase { UIUtil.dispatchAllInvocationEvents(); } - System.out.println("Average among the N/3 median times: " + PlatformTestUtil.averageAmongMedians(time, 3) + "ms"); + System.out.println("Average among the N/3 median times: " + ArrayUtil.averageAmongMedians(time, 3) + "ms"); //System.out.println("JobLauncher.COUNT = " + JobLauncher.COUNT); //System.out.println("JobLauncher.TINY = " + JobLauncher.TINY_COUNT); @@ -205,7 +205,7 @@ public class HighlightStressTest extends LightDaemonAnalyzerTestCase { } FileEditorManagerEx.getInstanceEx(getProject()).closeAllFiles(); - System.out.println("Average among the N/3 median times: " + PlatformTestUtil.averageAmongMedians(time, 3) + "ms"); + System.out.println("Average among the N/3 median times: " + ArrayUtil.averageAmongMedians(time, 3) + "ms"); } public void testRandomEditingForUnused() throws Exception { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java index caaa29162479..bd6866bf3f41 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java @@ -116,7 +116,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { alarm.cancelAllRequests(); } }, "", false, getProject(), null, ""); - long averageDelay = PlatformTestUtil.averageAmongMedians(times.toNativeArray(), 5); + long averageDelay = ArrayUtil.averageAmongMedians(times.toNativeArray(), 5); System.out.println("averageDelay = " + averageDelay); assertTrue(averageDelay < CoreProgressManager.CHECK_CANCELED_DELAY_MILLIS *3); } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index e67cbcbd6b67..317f7bdab61b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -415,19 +415,6 @@ public class PlatformTestUtil { return new TestInfo(test, expectedMs,message); } - // calculates average of the median values in the selected part of the array. E.g. for part=3 returns average in the middle third. - public static long averageAmongMedians(@NotNull long[] time, int part) { - assert part >= 1; - int n = time.length; - Arrays.sort(time); - long total = 0; - for (int i= n /2- n / part /2; i< n /2+ n / part /2; i++) { - total += time[i]; - } - int middlePartLength = n / part; - return middlePartLength == 0 ? 0 : total / middlePartLength; - } - public static boolean canRunTest(@NotNull Class testCaseClass) { if (!SKIP_SLOW && !SKIP_HEADLESS) { return true; diff --git a/platform/testFramework/src/com/intellij/testFramework/Timings.java b/platform/testFramework/src/com/intellij/testFramework/Timings.java index cb94d3236dd3..3afd1e3e9062 100644 --- a/platform/testFramework/src/com/intellij/testFramework/Timings.java +++ b/platform/testFramework/src/com/intellij/testFramework/Timings.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package com.intellij.testFramework; import com.intellij.concurrency.JobSchedulerImpl; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.ArrayUtil; import java.io.*; import java.math.BigInteger; @@ -49,7 +50,7 @@ public class Timings { for (int i=0; i< N; i++) { elapsed[i] = measureCPU(); } - CPU_TIMING = PlatformTestUtil.averageAmongMedians(elapsed, 2); + CPU_TIMING = ArrayUtil.averageAmongMedians(elapsed, 2); long start = System.currentTimeMillis(); for (int i = 0; i < IO_PROBES; i++) { diff --git a/platform/util/src/com/intellij/util/ArrayUtil.java b/platform/util/src/com/intellij/util/ArrayUtil.java index 2550a1d41d41..708222531bd6 100644 --- a/platform/util/src/com/intellij/util/ArrayUtil.java +++ b/platform/util/src/com/intellij/util/ArrayUtil.java @@ -900,4 +900,17 @@ public class ArrayUtil extends ArrayUtilRt { } return 0; } + + // calculates average of the median values in the selected part of the array. E.g. for part=3 returns average in the middle third. + public static long averageAmongMedians(@NotNull long[] time, int part) { + assert part >= 1; + int n = time.length; + Arrays.sort(time); + long total = 0; + for (int i= n /2- n / part /2; i< n /2+ n / part /2; i++) { + total += time[i]; + } + int middlePartLength = n / part; + return middlePartLength == 0 ? 0 : total / middlePartLength; + } }