Wrote a benchmark activity for Android which reads images recursively from the SD...
[zxing.git] / androidtest / src / com / google / zxing / client / androidtest / BenchmarkItem.java
1 /*
2  * Copyright (C) 2008 Google Inc.
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
17 package com.google.zxing.client.androidtest;
18
19 import com.google.zxing.BarcodeFormat;
20
21 public class BenchmarkItem {
22
23   private String mPath;
24   private int[] mTimes;
25   private int mPosition;
26   private boolean mDecoded;
27   private BarcodeFormat mFormat;
28
29   public BenchmarkItem(String path, int runs) {
30     mPath = path;
31     mTimes = new int[runs];
32     mPosition = 0;
33     mDecoded = false;
34     mFormat = null;
35   }
36
37   // I'm storing these separately instead of as a running total so I can add features like
38   // calculating the min and max later, or ignoring outliers.
39   public void addResult(int milliseconds) {
40     mTimes[mPosition] = milliseconds;
41     mPosition++;
42   }
43
44   public void setDecoded(boolean decoded) {
45     mDecoded = decoded;
46   }
47
48   public void setFormat(BarcodeFormat format) {
49     mFormat = format;
50   }
51
52   public String getPath() {
53     return mPath;
54   }
55
56   public int getAverageMilliseconds() {
57     int size = mTimes.length;
58     int total = 0;
59     for (int x = 0; x < size; x++) {
60       total += mTimes[x];
61     }
62     if (size > 0) {
63       return total / size;
64     } else {
65       return 0;
66     }
67   }
68
69   public int getCount() {
70     return mTimes.length;
71   }
72
73   public boolean getDecoded() {
74     return mDecoded;
75   }
76
77   public BarcodeFormat getFormat() {
78     return mFormat;
79   }
80
81 }