Index: pkg/analysis_server/test/timing/timing_framework.dart |
diff --git a/pkg/analysis_server/test/timing/timing_framework.dart b/pkg/analysis_server/test/timing/timing_framework.dart |
index d79b6bdc2d401b851cd9fc337bc3c6fe70be87f6..ffa47416cbf59fbeba335b0a1f7f2fddbded7c6a 100644 |
--- a/pkg/analysis_server/test/timing/timing_framework.dart |
+++ b/pkg/analysis_server/test/timing/timing_framework.dart |
@@ -14,28 +14,117 @@ import '../integration/integration_test_methods.dart'; |
import '../integration/integration_tests.dart'; |
/** |
- * The abstract class [TimingTest] defines the behavior of objects that measure |
- * the time required to perform some sequence of server operations. |
+ * Instances of the class [TimingResult] represent the timing information |
+ * gathered while executing a given timing test. |
*/ |
-abstract class TimingTest extends IntegrationTestMixin { |
+class TimingResult { |
/** |
- * The connection to the analysis server. |
+ * The number of nanoseconds in a millisecond. |
*/ |
- Server server; |
+ static int NANOSECONDS_PER_MILLISECOND = 1000000; |
/** |
- * The temporary directory in which source files can be stored. |
+ * The amount of time spent executing each test, in nanoseconds. |
*/ |
- Directory sourceDirectory; |
+ List<int> times; |
/** |
- * A flag indicating whether the teardown process should skip sending a |
- * "server.shutdown" request because the server is known to have already |
- * shutdown. |
+ * Initialize a newly created timing result. |
*/ |
- bool skipShutdown = false; |
+ TimingResult(this.times); |
+ |
+ /** |
+ * The average amount of time spent executing a single iteration, in |
+ * milliseconds. |
+ */ |
+ int get averageTime { |
+ return totalTime ~/ times.length; |
+ } |
+ |
+ /** |
+ * The maximum amount of time spent executing a single iteration, in |
+ * milliseconds. |
+ */ |
+ int get maxTime { |
+ int maxTime = 0; |
+ int count = times.length; |
+ for (int i = 0; i < count; i++) { |
+ maxTime = max(maxTime, times[i]); |
+ } |
+ return maxTime ~/ NANOSECONDS_PER_MILLISECOND; |
+ } |
+ |
+ /** |
+ * The minimum amount of time spent executing a single iteration, in |
+ * milliseconds. |
+ */ |
+ int get minTime { |
+ |
+ int minTime = times[0]; |
+ int count = times.length; |
+ for (int i = 1; i < count; i++) { |
+ minTime = min(minTime, times[i]); |
+ } |
+ return minTime ~/ NANOSECONDS_PER_MILLISECOND; |
+ } |
+ |
+ /** |
+ * The standard deviation of the times. |
+ */ |
+ double get standardDeviation { |
+ return computeStandardDeviation(toMilliseconds(times)); |
+ } |
+ |
+ /** |
+ * The total amount of time spent executing the test, in milliseconds. |
+ */ |
+ int get totalTime { |
+ int totalTime = 0; |
+ int count = times.length; |
+ for (int i = 0; i < count; i++) { |
+ totalTime += times[i]; |
+ } |
+ return totalTime ~/ NANOSECONDS_PER_MILLISECOND; |
+ } |
/** |
+ * Compute the standard deviation of the given set of [values]. |
+ */ |
+ double computeStandardDeviation(List<int> values) { |
+ int count = values.length; |
+ double sumOfValues = 0.0; |
+ for (int i = 0; i < count; i++) { |
+ sumOfValues += values[i]; |
+ } |
+ double average = sumOfValues / count; |
+ double sumOfDiffSquared = 0.0; |
+ for (int i = 0; i < count; i++) { |
+ double diff = values[i] - average; |
+ sumOfDiffSquared += diff * diff; |
+ } |
+ return sqrt((sumOfDiffSquared / (count - 1))); |
+ } |
+ |
+ /** |
+ * Convert the given [times], expressed in nanoseconds, to times expressed in |
+ * milliseconds. |
+ */ |
+ List<int> toMilliseconds(List<int> times) { |
+ int count = times.length; |
+ List<int> convertedValues = new List<int>(); |
+ for (int i = 0; i < count; i++) { |
+ convertedValues.add(times[i] ~/ NANOSECONDS_PER_MILLISECOND); |
+ } |
+ return convertedValues; |
+ } |
+} |
+ |
+/** |
+ * The abstract class [TimingTest] defines the behavior of objects that measure |
+ * the time required to perform some sequence of server operations. |
+ */ |
+abstract class TimingTest extends IntegrationTestMixin { |
+ /** |
* The number of times the test will be performed in order to warm up the VM. |
*/ |
static final int DEFAULT_WARMUP_COUNT = 10; |
@@ -62,15 +151,26 @@ abstract class TimingTest extends IntegrationTestMixin { |
static const Duration SHUTDOWN_TIMEOUT = const Duration(seconds: 5); |
/** |
- * Initialize a newly created test. |
+ * The connection to the analysis server. |
*/ |
- TimingTest(); |
+ Server server; |
/** |
- * Return the number of iterations that should be performed in order to warm |
- * up the VM. |
+ * The temporary directory in which source files can be stored. |
*/ |
- int get warmupCount => DEFAULT_WARMUP_COUNT; |
+ Directory sourceDirectory; |
+ |
+ /** |
+ * A flag indicating whether the teardown process should skip sending a |
+ * "server.shutdown" request because the server is known to have already |
+ * shutdown. |
+ */ |
+ bool skipShutdown = false; |
+ |
+ /** |
+ * Initialize a newly created test. |
+ */ |
+ TimingTest(); |
/** |
* Return the number of iterations that should be performed in order to |
@@ -79,6 +179,12 @@ abstract class TimingTest extends IntegrationTestMixin { |
int get timingCount => DEFAULT_TIMING_COUNT; |
/** |
+ * Return the number of iterations that should be performed in order to warm |
+ * up the VM. |
+ */ |
+ int get warmupCount => DEFAULT_WARMUP_COUNT; |
+ |
+ /** |
* Perform any operations that need to be performed once before any iterations. |
*/ |
Future oneTimeSetUp() { |
@@ -100,22 +206,6 @@ abstract class TimingTest extends IntegrationTestMixin { |
} |
/** |
- * Perform any operations that need to be performed before each iteration. |
- */ |
- Future setUp(); |
- |
- /** |
- * Perform any operations that part of a single iteration. It is the execution |
- * of this method that will be measured. |
- */ |
- Future perform(); |
- |
- /** |
- * Perform any operations that need to be performed after each iteration. |
- */ |
- Future tearDown(); |
- |
- /** |
* Perform any operations that need to be performed once after all iterations. |
*/ |
Future oneTimeTearDown() { |
@@ -125,6 +215,12 @@ abstract class TimingTest extends IntegrationTestMixin { |
} |
/** |
+ * Perform any operations that part of a single iteration. It is the execution |
+ * of this method that will be measured. |
+ */ |
+ Future perform(); |
+ |
+ /** |
* Return a future that will complete with a timing result representing the |
* number of milliseconds required to perform the operation the specified |
* number of times. |
@@ -143,6 +239,11 @@ abstract class TimingTest extends IntegrationTestMixin { |
} |
/** |
+ * Perform any operations that need to be performed before each iteration. |
+ */ |
+ Future setUp(); |
+ |
+ /** |
* Convert the given [relativePath] to an absolute path, by interpreting it |
* relative to [sourceDirectory]. On Windows any forward slashes in |
* [relativePath] are converted to backslashes. |
@@ -152,6 +253,11 @@ abstract class TimingTest extends IntegrationTestMixin { |
} |
/** |
+ * Perform any operations that need to be performed after each iteration. |
+ */ |
+ Future tearDown(); |
+ |
+ /** |
* Write a source file with the given absolute [pathname] and [contents]. |
* |
* If the file didn't previously exist, it is created. If it did, it is |
@@ -211,109 +317,3 @@ abstract class TimingTest extends IntegrationTestMixin { |
}); |
} |
} |
- |
-/** |
- * Instances of the class [TimingResult] represent the timing information |
- * gathered while executing a given timing test. |
- */ |
-class TimingResult { |
- /** |
- * The amount of time spent executing each test, in nanoseconds. |
- */ |
- List<int> times; |
- |
- /** |
- * The number of nanoseconds in a millisecond. |
- */ |
- static int NANOSECONDS_PER_MILLISECOND = 1000000; |
- |
- /** |
- * Initialize a newly created timing result. |
- */ |
- TimingResult(this.times); |
- |
- /** |
- * The average amount of time spent executing a single iteration, in |
- * milliseconds. |
- */ |
- int get averageTime { |
- return totalTime ~/ times.length; |
- } |
- |
- /** |
- * The maximum amount of time spent executing a single iteration, in |
- * milliseconds. |
- */ |
- int get maxTime { |
- int maxTime = 0; |
- int count = times.length; |
- for (int i = 0; i < count; i++) { |
- maxTime = max(maxTime, times[i]); |
- } |
- return maxTime ~/ NANOSECONDS_PER_MILLISECOND; |
- } |
- |
- /** |
- * The minimum amount of time spent executing a single iteration, in |
- * milliseconds. |
- */ |
- int get minTime { |
- |
- int minTime = times[0]; |
- int count = times.length; |
- for (int i = 1; i < count; i++) { |
- minTime = min(minTime, times[i]); |
- } |
- return minTime ~/ NANOSECONDS_PER_MILLISECOND; |
- } |
- |
- /** |
- * The standard deviation of the times. |
- */ |
- double get standardDeviation { |
- return computeStandardDeviation(toMilliseconds(times)); |
- } |
- |
- /** |
- * The total amount of time spent executing the test, in milliseconds. |
- */ |
- int get totalTime { |
- int totalTime = 0; |
- int count = times.length; |
- for (int i = 0; i < count; i++) { |
- totalTime += times[i]; |
- } |
- return totalTime ~/ NANOSECONDS_PER_MILLISECOND; |
- } |
- |
- /** |
- * Compute the standard deviation of the given set of [values]. |
- */ |
- double computeStandardDeviation(List<int> values) { |
- int count = values.length; |
- double sumOfValues = 0.0; |
- for (int i = 0; i < count; i++) { |
- sumOfValues += values[i]; |
- } |
- double average = sumOfValues / count; |
- double sumOfDiffSquared = 0.0; |
- for (int i = 0; i < count; i++) { |
- double diff = values[i] - average; |
- sumOfDiffSquared += diff * diff; |
- } |
- return sqrt((sumOfDiffSquared / (count - 1))); |
- } |
- |
- /** |
- * Convert the given [times], expressed in nanoseconds, to times expressed in |
- * milliseconds. |
- */ |
- List<int> toMilliseconds(List<int> times) { |
- int count = times.length; |
- List<int> convertedValues = new List<int>(); |
- for (int i = 0; i < count; i++) { |
- convertedValues.add(times[i] ~/ NANOSECONDS_PER_MILLISECOND); |
- } |
- return convertedValues; |
- } |
-} |