Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98e10b82 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add 90th and 95th percentile to ManualBenchmarkState"

parents 5d108838 3ffc6e7e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -150,6 +150,8 @@ public final class ManualBenchmarkState {
        final Bundle status = new Bundle();
        status.putLong(key + "_median", mStats.getMedian());
        status.putLong(key + "_mean", (long) mStats.getMean());
        status.putLong(key + "_percentile90", mStats.getPercentile90());
        status.putLong(key + "_percentile95", mStats.getPercentile95());
        status.putLong(key + "_stddev", (long) mStats.getStandardDeviation());
        instrumentation.sendStatus(Activity.RESULT_OK, status);
    }
+23 −4
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import java.util.Collections;
import java.util.List;

public class Stats {
    private long mMedian, mMin, mMax;
    private long mMedian, mMin, mMax, mPercentile90, mPercentile95;
    private double mMean, mStandardDeviation;

    /* Calculate stats in constructor. */
@@ -35,12 +35,14 @@ public class Stats {

        Collections.sort(values);

        mMedian = size % 2 == 0 ? (values.get(size / 2) + values.get(size / 2 - 1)) / 2 :
                values.get(size / 2);

        mMin = values.get(0);
        mMax = values.get(values.size() - 1);

        mMedian = size % 2 == 0 ? (values.get(size / 2) + values.get(size / 2 - 1)) / 2 :
                values.get(size / 2);
        mPercentile90 = getPercentile(values, 90);
        mPercentile95 = getPercentile(values, 95);

        for (int i = 0; i < size; ++i) {
            long result = values.get(i);
            mMean += result;
@@ -73,4 +75,21 @@ public class Stats {
    public double getStandardDeviation() {
        return mStandardDeviation;
    }

    public long getPercentile90() {
        return mPercentile90;
    }

    public long getPercentile95() {
        return mPercentile95;
    }

    private static long getPercentile(List<Long> values, int percentile) {
        if (percentile < 0 || percentile > 100) {
            throw new IllegalArgumentException(
                    "invalid percentile " + percentile + ", should be 0-100");
        }
        int idx = (values.size() - 1) * percentile / 100;
        return values.get(idx);
    }
}