/*
* MCS Media Computer Software Copyright (c) 2006 by MCS
* -------------------------------------- Created on 31.07.2006 by W.Klaas
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package de.mcs.jmeasurement.test;
import java.io.IOException;
import org.xml.sax.SAXException;
import de.mcs.jmeasurement.DefaultMonitor;
import de.mcs.jmeasurement.JMConfig;
import de.mcs.jmeasurement.MeasureFactory;
import de.mcs.jmeasurement.MeasurementException;
import de.mcs.jmeasurement.Monitor;
import de.mcs.jmeasurement.test.proxy.CTestProxy;
import de.mcs.jmeasurement.test.proxy.ITestProxy;
public class Performance {
private static final int POINT_COUNT = 100000;
private static final int CALL_COUNT = 100000;
/** prevent instancing. */
private Performance() {
}
public static void main(String[] args) throws MeasurementException {
perfJMeasure();
try {
MeasureFactory.saveToXMLFile("data.xml");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void perfJMeasure() throws MeasurementException {
String[] strings = new String[7];
System.out.println("JMeasurement performance test");
System.out
.println("Testing performance of creating "
+ Integer.toString(Performance.POINT_COUNT)
+ " measurepoints.");
DefaultMonitor monitor = null;
monitor = new DefaultMonitor(Integer.toString(Performance.POINT_COUNT)
+ "_Points");
monitor.start();
for (int i = 0; i < Performance.POINT_COUNT; i++) {
MeasureFactory.getMeasurePoint("test" + Integer.toString(i));
}
monitor.stop();
strings[0] = Long.toString(monitor.getAccrued());
System.out.println("1. Report: " + monitor.toString() + " msec");
System.out.println();
System.out.println("Testing perfomance to monitor "
+ Integer.toString(Performance.POINT_COUNT) + " calls.");
monitor = new DefaultMonitor(Integer.toString(Performance.POINT_COUNT)
+ "_Calls");
monitor.start();
for (int i = 0; i < Performance.POINT_COUNT; i++) {
Monitor monitor2 = MeasureFactory.start("test"
+ Integer.toString(i));
monitor2.stop();
}
monitor.stop();
strings[1] = Long.toString(monitor.getAccrued());
System.out.println("2. Report: " + monitor.toString() + " msec");
System.out.println();
System.out.println("Testing perfomance to monitor "
+ Integer.toString(Performance.POINT_COUNT)
+ " calls with factory disable.");
monitor = new DefaultMonitor(Integer.toString(Performance.POINT_COUNT)
+ "_Calls_disable");
MeasureFactory.setEnable(false);
monitor.start();
for (int i = 0; i < Performance.POINT_COUNT; i++) {
Monitor monitor2 = MeasureFactory.start("test"
+ Integer.toString(i));
monitor2.stop();
}
monitor.stop();
strings[2] = Long.toString(monitor.getAccrued());
System.out.println("3. Report: " + monitor.toString() + " msec");
System.out.println();
clearFactory();
System.out.println("Testing perfomance of interface methods: "
+ Integer.toString(Performance.CALL_COUNT)
+ " calls with factory enabled.");
monitor = new DefaultMonitor(Integer.toString(Performance.POINT_COUNT)
+ "_Proxy_enable");
MeasureFactory.setEnable(true);
ITestProxy testProxy = (ITestProxy) MeasureFactory.registerInterface(
new CTestProxy(), false, false);
monitor.start();
for (int i = 0; i < Performance.CALL_COUNT; i++) {
testProxy.iTestMethode("murks");
}
monitor.stop();
strings[3] = Long.toString(monitor.getAccrued());
System.out.println("4. Report: " + monitor.toString() + " msec");
System.out.println();
System.out.println("Point Report summary");
System.out.println(MeasureFactory.asString());
System.out.println("Testing perfomance of interface methods:"
+ Integer.toString(Performance.CALL_COUNT)
+ " calls with factory disabled.");
monitor = new DefaultMonitor(Integer.toString(Performance.POINT_COUNT)
+ "_Proxy_disable");
MeasureFactory.setEnable(false);
monitor.start();
for (int i = 0; i < Performance.CALL_COUNT; i++) {
testProxy.iTestMethode("murks");
}
monitor.stop();
strings[4] = Long.toString(monitor.getAccrued());
System.out.println("5. Report: " + monitor.toString() + " msec");
System.out.println();
System.out.println("Point Report summary");
System.out.println(MeasureFactory.asString());
MeasureFactory.setEnable(true);
clearFactory();
MeasureFactory.setOption(JMConfig.OPTION_DISABLE_DEVIATION,
Boolean.toString(true));
System.out.println("Testing perfomance of deviation calculation:"
+ Integer.toString(Performance.CALL_COUNT)
+ " calls with deviation disabled.");
Monitor monitor1;
monitor = new DefaultMonitor(Integer.toString(Performance.CALL_COUNT)
+ "_deviation_disable");
monitor.start();
for (int i = 0; i < Performance.CALL_COUNT; i++) {
monitor1 = MeasureFactory.start("test");
monitor1.stop();
}
monitor.stop();
strings[5] = Long.toString(monitor.getAccrued());
System.out.println("6. Report: " + monitor.toString() + " msec");
System.out.println();
System.out.println("Point Report summary");
System.out.println(MeasureFactory.asString());
clearFactory();
MeasureFactory.setOption(JMConfig.OPTION_DISABLE_DEVIATION,
Boolean.toString(true));
System.out.println("Testing perfomance of deviation calculation:"
+ Integer.toString(Performance.CALL_COUNT)
+ " calls with deviation enabled.");
monitor = new DefaultMonitor(Integer.toString(Performance.CALL_COUNT)
+ "_deviation_enabled");
monitor.start();
for (int i = 0; i < Performance.CALL_COUNT; i++) {
monitor1 = MeasureFactory.start("test");
monitor1.stop();
}
monitor.stop();
strings[6] = Long.toString(monitor.getAccrued());
System.out.println("7. Report: " + monitor.toString() + " msec");
System.out.println();
System.out.println("Point Report summary");
System.out.println(MeasureFactory.asString());
System.out.println("Report summary");
for (int i = 0; i < strings.length; i++) {
System.out.println(Integer.toString(i + 1) + ". :" + strings[i]
+ " msec");
}
}
private static void clearFactory() {
MeasureFactory.clear();
System.gc();
System.gc();
}
}
|