📄 performancetest.java
字号:
/*
* Copyright 2005-2007 the original author or authors.
*
* 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 net.sf.dozer.util.mapping;
import net.sf.dozer.util.mapping.util.TestDataFactory;
import net.sf.dozer.util.mapping.vo.SimpleObj;
import net.sf.dozer.util.mapping.vo.SimpleObjPrime;
import net.sf.dozer.util.mapping.vo.SimpleObjPrime2;
import net.sf.dozer.util.mapping.vo.TestObject;
import net.sf.dozer.util.mapping.vo.TestObjectPrime;
import net.sf.dozer.util.mapping.vo.deep.DestDeepObj;
import net.sf.dozer.util.mapping.vo.deep.SrcDeepObj;
import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClass;
import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClassPrime;
import org.apache.commons.lang.time.StopWatch;
import org.apache.log4j.Logger;
/**
* @author garsombke.franz
* @author sullins.ben
* @author tierney.matt
*
*/
public class PerformanceTest extends DozerTestBase {
private static Logger log = Logger.getLogger(PerformanceTest.class);
private int numIters = 1000;
private static MapperIF mapper;
protected void setUp() throws Exception {
super.setUp();
if (mapper == null) {
mapper = getNewMapper(new String[] { "dozerBeanMapping.xml" });
}
}
public static void main(String[] args) {
junit.textui.TestRunner.run(PerformanceTest.class);
}
/*
* Baseline Performance Numbers. Established with Release 2.0 - Jan 2006
*
* All baseline numbers based on 25000 numIters
*
* TEST TOTAL TIME(ms)
*
* testMapping1 19562
* testMapping2 2859
* testMapping3 2782
* testMapping4 8391
* testMapping5 4985
*
* MHT Computer - 8/12/06
* #1 17015
* #2 1954
* #3 1890
* #4 5985
* #5 4062
*
*/
public void testMapping1() throws Exception {
// TestObject --> TestObjectPrime
log.debug("Begin timings...");
TestObject src = TestDataFactory.getInputGeneralMappingTestObject();
runGeneric(src, TestObjectPrime.class, 22000);
}
public void testMapping2() throws Exception {
// SimpleObject --> SimpleObjectPrime
log.debug("Begin timings...");
SimpleObj src = (SimpleObj) TestDataFactory.getSimpleObj();
runGeneric(src, SimpleObjPrime.class, 3100);
}
public void testMapping3() throws Exception {
// SimpleObject --> SimpleObjectPrime2
log.debug("Begin timings...");
SimpleObj src = (SimpleObj) TestDataFactory.getSimpleObj();
runGeneric(src, SimpleObjPrime2.class, 3000);
}
public void testMapping4() throws Exception {
// AnotherSubClass --> AnotherSubClassPrime (Inheritance)
log.debug("Begin timings...");
AnotherSubClass src = TestDataFactory.getAnotherSubClass();
runGeneric(src, AnotherSubClassPrime.class, 9100);
}
public void testMapping5() throws Exception {
// SrcDeepObj --> DestDeepObj (Field Deep)
log.debug("Begin timings...");
SrcDeepObj src = TestDataFactory.getSrcDeepObj();
runGeneric(src, DestDeepObj.class, 5500);
}
private void runGeneric(Object src, Class destClass, long maxTimeAllowed) throws Exception {
// warm up the mapper
mapper.map(src, destClass);
// perform x number of additional mappings
StopWatch timer = new StopWatch();
timer.start();
for (int i = 0; i < numIters; i++) {
mapper.map(src, destClass);
}
timer.stop();
log.debug("Total time for additional " + numIters + " mappings: " + timer.getTime() + " milliseconds");
log.debug("avg time for " + numIters + " mappings: " + (timer.getTime() / numIters) + " milliseconds");
if (timer.getTime() > maxTimeAllowed) {
log.error("Elapsed time exceeded max allowed: " + maxTimeAllowed + " Actual time: " + timer.getTime());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -