2 * Copyright (C) 2008 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.client.androidtest;
19 import com.google.zxing.BarcodeFormat;
21 public final class BenchmarkItem {
23 private final String mPath;
24 private final int[] mTimes;
25 private int mPosition;
26 private boolean mDecoded;
27 private BarcodeFormat mFormat;
29 public BenchmarkItem(String path, int runs) {
31 throw new IllegalArgumentException();
34 mTimes = new int[runs];
40 public void addResult(int microseconds) {
41 mTimes[mPosition] = microseconds;
45 public void setDecoded(boolean decoded) {
49 public void setFormat(BarcodeFormat format) {
54 public String toString() {
55 StringBuilder result = new StringBuilder();
56 result.append(mDecoded ? ("DECODED " + mFormat.toString() + ": ") : "FAILED: ");
59 result.append(getAverageTime());
60 result.append(" us average)");
61 // int size = mTimes.length;
62 // for (int x = 0; x < size; x++) {
63 // result.append(mTimes[x]);
64 // result.append(" ");
66 return result.toString();
70 * Calculates the average time but throws out the maximum as an outlier first.
72 * @return The average decoding time in microseconds.
74 public int getAverageTime() {
75 int size = mTimes.length;
78 for (int x = 0; x < size; x++) {