1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.rs.imagejb;
18
19import java.util.ArrayList;
20
21class Result {
22
23    private ArrayList<Float> timeList;
24
25    Result() {
26        timeList = new ArrayList<Float>();
27    }
28
29    // Add time
30    public void add(float time) {
31        timeList.add(time);
32    }
33
34    // Get total execution time
35    public float getTotalTime() {
36        float total = 0.0f;
37        for (float time : timeList) {
38            total += time;
39        }
40        return total;
41    }
42
43    // Get number of iterations
44    public int getIterations() {
45        return timeList.size();
46    }
47
48    // Get the average of an array list
49    public float getAvg() {
50        return getTotalTime() / getIterations();
51    }
52
53    // Get the biased ("full population") standard deviation
54    public float getStdevp() {
55        float sumSqDiff = 0;
56        float avg = getAvg();
57        for (float time : timeList) {
58            float diff = time - avg;
59            sumSqDiff += diff * diff;
60        }
61        return (float) Math.sqrt(sumSqDiff / getIterations());
62    }
63
64    // Get the normalized standard deviation ("standard deviation coefficient")
65    public float getStdCoef() {
66        return getStdevp() / getAvg();
67    }
68
69    // Get all times as float[]
70    public float[] getTimes() {
71        float[] array = new float[getIterations()];
72        for (int i = 0; i < getIterations(); i++) {
73            array[i] = timeList.get(i);
74        }
75        return array;
76    }
77}
78