summaryrefslogtreecommitdiff
path: root/startop/apps
diff options
context:
space:
mode:
authorEric Holk <eholk@google.com>2019-09-10 14:22:12 -0700
committerEric Holk <eholk@google.com>2019-09-10 14:22:12 -0700
commit4777ee062110421089b8eb8bd64b383937cf1739 (patch)
tree102c7c42aa87edcf2d2d9175fd1aa4b20ce2b3f3 /startop/apps
parent13926c385c8ca606d9acd8a969a73dc29edd7413 (diff)
Run system_server benchmarks for 5 seconds
Especially for short running methods, this gives us better results and also gives us more data for things like simpleperf to work on. Since we don't know ahead of time how many times each benchmark will run, we had to switch the mean and standard deviation formulas to one that supports running updates. This has the advantage of making it constant space. Bug: 140743821 Change-Id: I3e6b6b44d3bd573bad8afc8831226194147b108a
Diffstat (limited to 'startop/apps')
-rw-r--r--startop/apps/test/src/SystemServerBenchmarkActivity.java32
1 files changed, 15 insertions, 17 deletions
diff --git a/startop/apps/test/src/SystemServerBenchmarkActivity.java b/startop/apps/test/src/SystemServerBenchmarkActivity.java
index c370924c943c..61d43226c41e 100644
--- a/startop/apps/test/src/SystemServerBenchmarkActivity.java
+++ b/startop/apps/test/src/SystemServerBenchmarkActivity.java
@@ -35,7 +35,8 @@ import android.widget.TextView;
import java.util.Arrays;
class Benchmark {
- public static final int NUM_ITERATIONS = 1000;
+ // Time limit to run benchmarks in seconds
+ public static final int TIME_LIMIT = 5;
public Benchmark(ViewGroup parent, CharSequence name, Runnable thunk) {
Context context = parent.getContext();
@@ -57,28 +58,25 @@ class Benchmark {
@Override
protected Object doInBackground(Object... _args) {
- long[] results = new long[NUM_ITERATIONS];
+ long startTime = System.nanoTime();
+ int count = 0;
// Run benchmark
- for (int i = 0; i < results.length; i++) {
- results[i] = -System.nanoTime();
+ while (true) {
+ long elapsed = -System.nanoTime();
thunk.run();
- results[i] += System.nanoTime();
- }
+ elapsed += System.nanoTime();
- // Compute mean
- long sum = Arrays.stream(results).sum();
- resultMean = (double) sum / results.length;
+ count++;
+ double elapsedVariance = (double) elapsed - resultMean;
+ resultMean += elapsedVariance / count;
+ resultStdev += elapsedVariance * ((double) elapsed - resultMean);
- // Compute standard deviation
- double variance = 0;
- for (long i : results) {
- double t = (double) i - resultMean;
- variance += t * t;
+ if (System.nanoTime() - startTime > TIME_LIMIT * 1e9) {
+ break;
+ }
}
- variance /= results.length - 1;
-
- resultStdev = Math.sqrt(variance);
+ resultStdev = Math.sqrt(resultStdev / (count - 1));
return null;
}