14a40b82759be72849f83c103b77f20ea29e160e5Michael Butler/* 24a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * Copyright (C) 2016 The Android Open Source Project 34a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * 44a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * Licensed under the Apache License, Version 2.0 (the "License"); 54a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * you may not use this file except in compliance with the License. 64a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * You may obtain a copy of the License at 74a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * 84a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * http://www.apache.org/licenses/LICENSE-2.0 94a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * 104a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * Unless required by applicable law or agreed to in writing, software 114a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * distributed under the License is distributed on an "AS IS" BASIS, 124a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * See the License for the specific language governing permissions and 144a40b82759be72849f83c103b77f20ea29e160e5Michael Butler * limitations under the License. 154a40b82759be72849f83c103b77f20ea29e160e5Michael Butler */ 164a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 174a40b82759be72849f83c103b77f20ea29e160e5Michael Butlerpackage com.android.rs.imagejb; 184a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 194a40b82759be72849f83c103b77f20ea29e160e5Michael Butlerimport java.util.ArrayList; 204a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 214a40b82759be72849f83c103b77f20ea29e160e5Michael Butlerclass Result { 224a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 234a40b82759be72849f83c103b77f20ea29e160e5Michael Butler private ArrayList<Float> timeList; 244a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 254a40b82759be72849f83c103b77f20ea29e160e5Michael Butler Result() { 264a40b82759be72849f83c103b77f20ea29e160e5Michael Butler timeList = new ArrayList<Float>(); 274a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 284a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 294a40b82759be72849f83c103b77f20ea29e160e5Michael Butler // Add time 304a40b82759be72849f83c103b77f20ea29e160e5Michael Butler public void add(float time) { 314a40b82759be72849f83c103b77f20ea29e160e5Michael Butler timeList.add(time); 324a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 334a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 344a40b82759be72849f83c103b77f20ea29e160e5Michael Butler // Get total execution time 354a40b82759be72849f83c103b77f20ea29e160e5Michael Butler public float getTotalTime() { 364a40b82759be72849f83c103b77f20ea29e160e5Michael Butler float total = 0.0f; 374a40b82759be72849f83c103b77f20ea29e160e5Michael Butler for (float time : timeList) { 384a40b82759be72849f83c103b77f20ea29e160e5Michael Butler total += time; 394a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 404a40b82759be72849f83c103b77f20ea29e160e5Michael Butler return total; 414a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 424a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 434a40b82759be72849f83c103b77f20ea29e160e5Michael Butler // Get number of iterations 444a40b82759be72849f83c103b77f20ea29e160e5Michael Butler public int getIterations() { 454a40b82759be72849f83c103b77f20ea29e160e5Michael Butler return timeList.size(); 464a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 474a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 484a40b82759be72849f83c103b77f20ea29e160e5Michael Butler // Get the average of an array list 494a40b82759be72849f83c103b77f20ea29e160e5Michael Butler public float getAvg() { 504a40b82759be72849f83c103b77f20ea29e160e5Michael Butler return getTotalTime() / getIterations(); 514a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 524a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 534a40b82759be72849f83c103b77f20ea29e160e5Michael Butler // Get the biased ("full population") standard deviation 544a40b82759be72849f83c103b77f20ea29e160e5Michael Butler public float getStdevp() { 554a40b82759be72849f83c103b77f20ea29e160e5Michael Butler float sumSqDiff = 0; 564a40b82759be72849f83c103b77f20ea29e160e5Michael Butler float avg = getAvg(); 574a40b82759be72849f83c103b77f20ea29e160e5Michael Butler for (float time : timeList) { 584a40b82759be72849f83c103b77f20ea29e160e5Michael Butler float diff = time - avg; 594a40b82759be72849f83c103b77f20ea29e160e5Michael Butler sumSqDiff += diff * diff; 604a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 614a40b82759be72849f83c103b77f20ea29e160e5Michael Butler return (float) Math.sqrt(sumSqDiff / getIterations()); 624a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 634a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 644a40b82759be72849f83c103b77f20ea29e160e5Michael Butler // Get the normalized standard deviation ("standard deviation coefficient") 654a40b82759be72849f83c103b77f20ea29e160e5Michael Butler public float getStdCoef() { 664a40b82759be72849f83c103b77f20ea29e160e5Michael Butler return getStdevp() / getAvg(); 674a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 684a40b82759be72849f83c103b77f20ea29e160e5Michael Butler 694a40b82759be72849f83c103b77f20ea29e160e5Michael Butler // Get all times as float[] 704a40b82759be72849f83c103b77f20ea29e160e5Michael Butler public float[] getTimes() { 714a40b82759be72849f83c103b77f20ea29e160e5Michael Butler float[] array = new float[getIterations()]; 724a40b82759be72849f83c103b77f20ea29e160e5Michael Butler for (int i = 0; i < getIterations(); i++) { 734a40b82759be72849f83c103b77f20ea29e160e5Michael Butler array[i] = timeList.get(i); 744a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 754a40b82759be72849f83c103b77f20ea29e160e5Michael Butler return array; 764a40b82759be72849f83c103b77f20ea29e160e5Michael Butler } 774a40b82759be72849f83c103b77f20ea29e160e5Michael Butler} 78