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;
25 private int mPosition;
26 private boolean mDecoded;
27 private BarcodeFormat mFormat;
29 public BenchmarkItem(String path, int runs) {
32 mTimes = new int[runs];
38 public final void addResult(int microseconds) {
39 mTimes[mPosition] = microseconds;
43 public final void setDecoded(boolean decoded) {
47 public final void setFormat(BarcodeFormat format) {
52 public final String toString() {
53 StringBuffer result = new StringBuffer();
54 result.append(mDecoded ? ("DECODED " + mFormat.toString() + ": ") : "FAILED: ");
57 result.append(getAverageTime());
58 result.append(" us average)");
59 // int size = mTimes.length;
60 // for (int x = 0; x < size; x++) {
61 // result.append(mTimes[x]);
62 // result.append(" ");
64 return result.toString();
68 * Calculates the average time but throws out the maximum as an outlier first.
70 * @return The average decoding time in microseconds.
72 private int getAverageTime() {
73 int size = mTimes.length;
76 for (int x = 0; x < size; x++) {