001: /*
002: * Copyright 2005-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package net.sf.dozer.functional_tests;
017:
018: import net.sf.dozer.util.mapping.MapperIF;
019: import net.sf.dozer.util.mapping.vo.SimpleObj;
020: import net.sf.dozer.util.mapping.vo.SimpleObjPrime;
021: import net.sf.dozer.util.mapping.vo.SimpleObjPrime2;
022: import net.sf.dozer.util.mapping.vo.TestObject;
023: import net.sf.dozer.util.mapping.vo.TestObjectPrime;
024: import net.sf.dozer.util.mapping.vo.deep.DestDeepObj;
025: import net.sf.dozer.util.mapping.vo.deep.SrcDeepObj;
026: import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClass;
027: import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClassPrime;
028: import net.sf.dozer.util.mapping.vo.perf.MyClassA;
029: import net.sf.dozer.util.mapping.vo.perf.MyClassB;
030:
031: import org.apache.commons.lang.time.StopWatch;
032: import org.apache.commons.logging.Log;
033: import org.apache.commons.logging.LogFactory;
034:
035: /**
036: * @author tierney.matt
037: * @author garsombke.franz
038: */
039: public class PerformanceTest extends AbstractMapperTest {
040: private static Log log = LogFactory.getLog(PerformanceTest.class);
041: private static MapperIF mapper;
042:
043: private int numIters = 1;
044:
045: protected void setUp() throws Exception {
046: super .setUp();
047: if (mapper == null) {
048: mapper = getMapper(new String[] { "dozerBeanMapping.xml" });
049: }
050: }
051:
052: /*
053: * Baseline Performance Numbers. Established with Release 2.0 - Jan 2006
054: *
055: * All performance results based on 25000 numIters and jdk 1.4.2(unless otherwise specified)
056: *
057: * TEST TOTAL TIME(ms) - 1/1/06
058: *
059: * testMapping1 19562 testMapping2 2859 testMapping3 2782 testMapping4 8391 testMapping5 4985
060: *
061: *
062: * MHT Computer - 8/12/06
063: * #1 17015 #2 1954 #3 1890 #4 5985 #5 4062
064: *
065: *
066: * MHT Computer - 9/26/06 - After 2.3 release
067: * #1 19578 #2 1937 #3 1953 #4 6734 #5 4641
068: *
069: *
070: * MHT Computer - 10/1/06 - 2.4 release. After removing Reflection caching to resolve general CGLIB/Proxy issues
071: * #1 29313 #2 2985 #3 3130 #4 9891 #5 7656
072: *
073: *
074: * MHT Computer - 12/20/06 - 2.5 release. After adding code submitted for fixing recursive mapping infinite loop
075: * problem. Due to maintaining mappedFields variable in MappingProcessor. Is this ok or better way to do it? Not sure
076: * #1 31422 #2 3485 #3 3547 #4 11656 #5 8281
077: *
078: *
079: * MHT Computer - 1/26/07 - 2.5 release. After making misc perf improvements to improve test case #6
080: * #1 26047 #2 3375 #3 3469 #4 11672 #5 7516 #6 45850
081: *
082: *
083: * MHT Computer - 2/1/07 - 2.5 release. Just prior to release of 2.5
084: * #1 26266 #2 3094 #3 3203 #4 11297 #5 7453 #6 42312
085: *
086: *
087: * MHT Computer - 4/2/07 - 3.2 release.
088: * #1 24891 #2 3125 #3 3219 #4 10609 #5 7328 #6 45156
089: *
090: *
091: * MHT Computer - 4/7/07 - 3.2.1 release.
092: * jdk1.4 #1 25391 #2 3094 #3 3156 #4 10516 #5 7406 #6 44922
093: * jdk1.5 #1 24016 #2 2797 #3 2890 #4 10031 #5 7125 #6 41797
094: *
095: *
096: * MHT Computer - 4/19/07 - 3.2.1 release. Rebaseline test #6. Unused and Uneccessary test data setup logic was
097: * skewing prior results.
098: * jdk1.4 #1 25391 #2 3094 #3 3156 #4 10516 #5 7406 #6 31687
099: * jdk1.5 #1 24016 #2 2797 #3 2890 #4 10031 #5 7125 #6 26265
100: *
101: *
102: * MHT Computer - 4/24/07 - 3.3 release
103: * jdk1.4 #1 25485 #2 2907 #3 3219 #4 10375 #5 7312 #6 33703
104: * jdk1.5 #1 23172 #2 2406 #3 2750 #4 9817 #5 6771 #6 26718
105: *
106: *
107: * MHT Computer - 5/16/07 - 3.4 release
108: * jdk1.4 #1 27854 #2 2945 #3 3123 #4 11844 #5 8437 #6 19567
109: * jdk1.5 #1 27485 #2 2532 #3 2906 #4 11297 #5 8157 #6 16797
110: *
111: *
112: * MHT Computer - 7/06/07 - 4.0 release after map backed property refactor
113: * jdk1.4 #1 27047 #2 3140 #3 3172 #4 12328 #5 8359 #6 33281
114: * jdk1.5 #1 26484 #2 3016 #3 3062 #4 11781 #5 7906 #6 30594
115: *
116: *
117: * MHT Computer - 7/15/07 - 4.0 release
118: * jdk1.4 #1 24078 #2 2844 #3 2891 #4 11656 #5 7797 #6 36156
119: * jdk1.5 #1 24625 #2 2656 #3 2688 #4 11515 #5 7781 #6 31797
120: *
121: * MHT Computer - 9/25/07 - 4.1 release
122: * jdk1.4 #1 25766 #2 2938 #3 3000 #4 12078 #5 8156 #6 36031
123: * jdk1.5 #1 24516 #2 2578 #3 2672 #4 11671 #5 7875 #6 32000
124: *
125: * MHT Computer - 12/15/07 - 4.2 release
126: * jdk1.4 #1 23937 #2 2781 #3 2781 #4 11696 #5 7687 #6 36953
127: * jdk1.5 #1 24157 #2 2594 #3 2640 #4 12438 #5 7984 #6 34531
128: *
129: */
130:
131: public void testMapping1() throws Exception {
132: // TestObject --> TestObjectPrime
133: TestObject src = testDataFactory
134: .getInputGeneralMappingTestObject();
135: runGeneric("testMapping1", src, TestObjectPrime.class, 35000);
136: }
137:
138: public void testMapping2() throws Exception {
139: // SimpleObject --> SimpleObjectPrime
140: SimpleObj src = testDataFactory.getSimpleObj();
141: runGeneric("testMapping2", src, SimpleObjPrime.class, 3600);
142: }
143:
144: public void testMapping3() throws Exception {
145: // SimpleObject --> SimpleObjectPrime2
146: SimpleObj src = testDataFactory.getSimpleObj();
147: runGeneric("testMapping3", src, SimpleObjPrime2.class, 3700);
148: }
149:
150: public void testMapping4() throws Exception {
151: // AnotherSubClass --> AnotherSubClassPrime (Inheritance)
152: AnotherSubClass src = testDataFactory.getAnotherSubClass();
153: runGeneric("testMapping4", src, AnotherSubClassPrime.class,
154: 12000);
155: }
156:
157: public void testMapping5() throws Exception {
158: // SrcDeepObj --> DestDeepObj (Field Deep)
159: SrcDeepObj src = testDataFactory.getSrcDeepObj();
160: runGeneric("testMapping5", src, DestDeepObj.class, 9000);
161: }
162:
163: // 1-2007: Test Case submitted by Dave B.
164: public void testMapping6() throws Exception {
165: // MyClassA --> MyClassB. Src object contains List with 500 String elements.
166: MyClassA src = testDataFactory.getRandomMyClassA();
167: runGeneric("testMapping6", src, MyClassB.class, 50000);
168: }
169:
170: protected DataObjectInstantiator getDataObjectInstantiator() {
171: return NoProxyDataObjectInstantiator.INSTANCE;
172: }
173:
174: private void runGeneric(String testName, Object src,
175: Class destClass, long maxTimeAllowed) throws Exception {
176: // warm up the mapper
177: mapper.map(src, destClass);
178:
179: // perform x number of additional mappings
180: log.debug("Begin timings for " + testName);
181: StopWatch timer = new StopWatch();
182: timer.start();
183: for (int i = 0; i < numIters; i++) {
184: mapper.map(src, destClass);
185: }
186: timer.stop();
187: log.debug("Total time for additional " + numIters
188: + " mappings: " + timer.getTime() + " milliseconds");
189: log.debug("avg time for " + numIters + " mappings: "
190: + (timer.getTime() / numIters) + " milliseconds");
191:
192: if (timer.getTime() > maxTimeAllowed) {
193: log.error("Elapsed time exceeded max allowed: "
194: + maxTimeAllowed + " Actual time: "
195: + timer.getTime());
196: }
197: }
198:
199: /* public static void main(String[] args) {
200: junit.textui.TestRunner.run(PerformanceTest.class);
201: }*/
202:
203: }
|