001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.performance.results;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.HashSet;
047: import java.util.Iterator;
048: import java.util.Set;
049:
050: /** Wrapper for inforamtion about one performance test case.
051: *
052: * @author Radim Kubacki
053: */
054: public class TestResult implements Comparable {
055:
056: public static final int ORDER_FIRST = 1;
057: public static final int ORDER_NEXT = 2;
058:
059: /** updates mean and variances. */
060: public static Statistics computeStatistics(
061: Collection<Integer> values) {
062: Statistics s = new Statistics();
063:
064: s.n = values.size();
065: s.avg = s.stddev = s.var = s.sumSquares = 0;
066: for (int val : values) {
067: s.avg += val;
068: s.sumSquares += val * val;
069: }
070:
071: // ep = 0.0;
072: // for (i = 2; i <= n; i++) {
073: // s = ARGV[i] - mean;
074: // ep += s;
075: // variance = variance + s * s;
076: // }
077: // variance = (variance - ep*ep/n)/(n - 1);
078: // stdev = sqrt(variance);
079: // printf("stdev=%f\n", stdev);
080: // printf("var=%f\n", variance);
081: //
082: if (s.n > 0) {
083: s.avg = s.avg / s.n;
084: }
085: if (s.n > 1) {
086: double ep = 0d;
087: for (int v : values) {
088: ep += v - s.avg;
089: s.var += (v - s.avg) * (v - s.avg);
090: }
091: s.var = (s.var - ep * ep / s.n) / (s.n - 1);
092: s.stddev = Math.sqrt(s.var);
093:
094: }
095: return s;
096: }
097:
098: /** Name of test case. */
099: String name;
100: /** Expected limit for result values. */
101: int threshold;
102: /** Measurement unit. */
103: String unit;
104: /** Order of test case in measured suite. */
105: int order;
106:
107: private String suite;
108:
109: /** Creates a new instance of TestCaseResults */
110: public TestResult(String name, int threshold, String unit,
111: int order, String suite) {
112: if (name == null || unit == null)
113: throw new IllegalArgumentException();
114:
115: this .name = name;
116: this .unit = unit;
117: this .threshold = threshold;
118: this .order = order;
119: this .suite = (suite != null) ? suite : "";
120: }
121:
122: public static class Statistics {
123: /** computed average */
124: private double avg;
125:
126: /** computed standard deviation */
127: private double stddev;
128:
129: /** computed variance */
130: private double var;
131:
132: private double sumSquares;
133:
134: /** count of values */
135: private int n;
136:
137: public double getAverage() {
138: return avg;
139: }
140:
141: public double getStdDev() {
142: return stddev;
143: }
144:
145: public double getVariance() {
146: return var;
147: }
148:
149: public int getCount() {
150: return n;
151: }
152:
153: // public double getSumSquares () {
154: // return sumSquares;
155: // }
156: }
157:
158: /**
159: * Getter for property name.
160: * @return Value of property name.
161: */
162: public java.lang.String getName() {
163: return name;
164: }
165:
166: /**
167: * Getter for property threshold.
168: * @return Value of property threshold.
169: */
170: public int getThreshold() {
171: return threshold;
172: }
173:
174: /**
175: * Getter for property unit.
176: * @return Value of property unit.
177: */
178: public java.lang.String getUnit() {
179: return unit;
180: }
181:
182: public int hashCode() {
183: return name.hashCode() | unit.hashCode() | order | threshold;
184: }
185:
186: public boolean equals(Object obj) {
187: if (!(obj instanceof TestResult))
188: return false;
189:
190: TestResult o = (TestResult) obj;
191: return suite.equals(o.suite) && name.equals(o.name)
192: && threshold == o.threshold && unit.equals(o.unit)
193: && order == o.order;
194: }
195:
196: /**
197: * Getter for property order.
198: * @return Value of property order.
199: */
200: public int getOrder() {
201: return order;
202: }
203:
204: public int compareTo(Object o) {
205: TestResult t = (TestResult) o;
206: if (suite.equals(t.suite)) {
207: if (name.equals(t.name)) {
208: if (order == t.order) {
209: if (unit.equals(t.unit)) {
210: return threshold - t.threshold;
211: } else {
212: return unit.compareTo(t.unit);
213: }
214: } else {
215: return (order > t.order) ? 1 : -1;
216: }
217: } else {
218: return name.compareTo(t.name);
219: }
220: } else {
221: return suite.compareTo(t.suite);
222: }
223: }
224:
225: }
|