001: /*
002: * MCS Media Computer Software Copyright (c) 2006 by MCS
003: * -------------------------------------- Created on 31.07.2006 by W.Klaas
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006: * use this file except in compliance with the License. You may obtain a copy of
007: * the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017: package de.mcs.jmeasurement.test;
018:
019: import java.io.IOException;
020:
021: import org.xml.sax.SAXException;
022:
023: import de.mcs.jmeasurement.DefaultMonitor;
024: import de.mcs.jmeasurement.JMConfig;
025: import de.mcs.jmeasurement.MeasureFactory;
026: import de.mcs.jmeasurement.MeasurementException;
027: import de.mcs.jmeasurement.Monitor;
028: import de.mcs.jmeasurement.test.proxy.CTestProxy;
029: import de.mcs.jmeasurement.test.proxy.ITestProxy;
030:
031: public class Performance {
032:
033: private static final int POINT_COUNT = 100000;
034:
035: private static final int CALL_COUNT = 100000;
036:
037: /** prevent instancing. */
038: private Performance() {
039: }
040:
041: public static void main(String[] args) throws MeasurementException {
042: perfJMeasure();
043: try {
044: MeasureFactory.saveToXMLFile("data.xml");
045: } catch (IOException e) {
046: // TODO Auto-generated catch block
047: e.printStackTrace();
048: } catch (SAXException e) {
049: // TODO Auto-generated catch block
050: e.printStackTrace();
051: }
052: }
053:
054: private static void perfJMeasure() throws MeasurementException {
055: String[] strings = new String[7];
056: System.out.println("JMeasurement performance test");
057: System.out.println("Testing performance of creating "
058: + Integer.toString(Performance.POINT_COUNT)
059: + " measurepoints.");
060: DefaultMonitor monitor = null;
061: monitor = new DefaultMonitor(Integer
062: .toString(Performance.POINT_COUNT)
063: + "_Points");
064: monitor.start();
065: for (int i = 0; i < Performance.POINT_COUNT; i++) {
066: MeasureFactory
067: .getMeasurePoint("test" + Integer.toString(i));
068: }
069: monitor.stop();
070: strings[0] = Long.toString(monitor.getAccrued());
071: System.out
072: .println("1. Report: " + monitor.toString() + " msec");
073: System.out.println();
074:
075: System.out
076: .println("Testing perfomance to monitor "
077: + Integer.toString(Performance.POINT_COUNT)
078: + " calls.");
079: monitor = new DefaultMonitor(Integer
080: .toString(Performance.POINT_COUNT)
081: + "_Calls");
082: monitor.start();
083: for (int i = 0; i < Performance.POINT_COUNT; i++) {
084: Monitor monitor2 = MeasureFactory.start("test"
085: + Integer.toString(i));
086: monitor2.stop();
087: }
088: monitor.stop();
089: strings[1] = Long.toString(monitor.getAccrued());
090: System.out
091: .println("2. Report: " + monitor.toString() + " msec");
092: System.out.println();
093:
094: System.out.println("Testing perfomance to monitor "
095: + Integer.toString(Performance.POINT_COUNT)
096: + " calls with factory disable.");
097: monitor = new DefaultMonitor(Integer
098: .toString(Performance.POINT_COUNT)
099: + "_Calls_disable");
100: MeasureFactory.setEnable(false);
101: monitor.start();
102: for (int i = 0; i < Performance.POINT_COUNT; i++) {
103: Monitor monitor2 = MeasureFactory.start("test"
104: + Integer.toString(i));
105: monitor2.stop();
106: }
107: monitor.stop();
108: strings[2] = Long.toString(monitor.getAccrued());
109: System.out
110: .println("3. Report: " + monitor.toString() + " msec");
111: System.out.println();
112: clearFactory();
113:
114: System.out.println("Testing perfomance of interface methods: "
115: + Integer.toString(Performance.CALL_COUNT)
116: + " calls with factory enabled.");
117: monitor = new DefaultMonitor(Integer
118: .toString(Performance.POINT_COUNT)
119: + "_Proxy_enable");
120: MeasureFactory.setEnable(true);
121: ITestProxy testProxy = (ITestProxy) MeasureFactory
122: .registerInterface(new CTestProxy(), false, false);
123: monitor.start();
124: for (int i = 0; i < Performance.CALL_COUNT; i++) {
125: testProxy.iTestMethode("murks");
126: }
127: monitor.stop();
128: strings[3] = Long.toString(monitor.getAccrued());
129: System.out
130: .println("4. Report: " + monitor.toString() + " msec");
131: System.out.println();
132: System.out.println("Point Report summary");
133: System.out.println(MeasureFactory.asString());
134:
135: System.out.println("Testing perfomance of interface methods:"
136: + Integer.toString(Performance.CALL_COUNT)
137: + " calls with factory disabled.");
138: monitor = new DefaultMonitor(Integer
139: .toString(Performance.POINT_COUNT)
140: + "_Proxy_disable");
141: MeasureFactory.setEnable(false);
142: monitor.start();
143: for (int i = 0; i < Performance.CALL_COUNT; i++) {
144: testProxy.iTestMethode("murks");
145: }
146: monitor.stop();
147: strings[4] = Long.toString(monitor.getAccrued());
148: System.out
149: .println("5. Report: " + monitor.toString() + " msec");
150: System.out.println();
151: System.out.println("Point Report summary");
152: System.out.println(MeasureFactory.asString());
153:
154: MeasureFactory.setEnable(true);
155: clearFactory();
156: MeasureFactory.setOption(JMConfig.OPTION_DISABLE_DEVIATION,
157: Boolean.toString(true));
158:
159: System.out
160: .println("Testing perfomance of deviation calculation:"
161: + Integer.toString(Performance.CALL_COUNT)
162: + " calls with deviation disabled.");
163: Monitor monitor1;
164: monitor = new DefaultMonitor(Integer
165: .toString(Performance.CALL_COUNT)
166: + "_deviation_disable");
167: monitor.start();
168: for (int i = 0; i < Performance.CALL_COUNT; i++) {
169: monitor1 = MeasureFactory.start("test");
170: monitor1.stop();
171: }
172: monitor.stop();
173: strings[5] = Long.toString(monitor.getAccrued());
174: System.out
175: .println("6. Report: " + monitor.toString() + " msec");
176: System.out.println();
177:
178: System.out.println("Point Report summary");
179: System.out.println(MeasureFactory.asString());
180: clearFactory();
181: MeasureFactory.setOption(JMConfig.OPTION_DISABLE_DEVIATION,
182: Boolean.toString(true));
183:
184: System.out
185: .println("Testing perfomance of deviation calculation:"
186: + Integer.toString(Performance.CALL_COUNT)
187: + " calls with deviation enabled.");
188: monitor = new DefaultMonitor(Integer
189: .toString(Performance.CALL_COUNT)
190: + "_deviation_enabled");
191: monitor.start();
192: for (int i = 0; i < Performance.CALL_COUNT; i++) {
193: monitor1 = MeasureFactory.start("test");
194: monitor1.stop();
195: }
196: monitor.stop();
197: strings[6] = Long.toString(monitor.getAccrued());
198: System.out
199: .println("7. Report: " + monitor.toString() + " msec");
200: System.out.println();
201: System.out.println("Point Report summary");
202: System.out.println(MeasureFactory.asString());
203:
204: System.out.println("Report summary");
205: for (int i = 0; i < strings.length; i++) {
206: System.out.println(Integer.toString(i + 1) + ". :"
207: + strings[i] + " msec");
208: }
209: }
210:
211: private static void clearFactory() {
212: MeasureFactory.clear();
213: System.gc();
214: System.gc();
215: }
216: }
|