KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > PerformanceTest


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping;
17
18 import net.sf.dozer.util.mapping.util.TestDataFactory;
19 import net.sf.dozer.util.mapping.vo.SimpleObj;
20 import net.sf.dozer.util.mapping.vo.SimpleObjPrime;
21 import net.sf.dozer.util.mapping.vo.SimpleObjPrime2;
22 import net.sf.dozer.util.mapping.vo.TestObject;
23 import net.sf.dozer.util.mapping.vo.TestObjectPrime;
24 import net.sf.dozer.util.mapping.vo.deep.DestDeepObj;
25 import net.sf.dozer.util.mapping.vo.deep.SrcDeepObj;
26 import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClass;
27 import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClassPrime;
28 import net.sf.dozer.util.mapping.vo.perf.MyClassA;
29 import net.sf.dozer.util.mapping.vo.perf.MyClassB;
30
31 import org.apache.commons.lang.time.StopWatch;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 /**
36  * @author garsombke.franz
37  * @author sullins.ben
38  * @author tierney.matt
39  *
40  */

41 public class PerformanceTest extends DozerTestBase {
42
43   private static Log log = LogFactory.getLog(PerformanceTest.class);
44
45   private int numIters = 10;
46   
47   private static MapperIF mapper;
48
49   protected void setUp() throws Exception JavaDoc {
50     super.setUp();
51     if (mapper == null) {
52       mapper = getNewMapper(new String JavaDoc[] { "dozerBeanMapping.xml" });
53     }
54   }
55
56   /*
57    * Baseline Performance Numbers. Established with Release 2.0 - Jan 2006
58    *
59    * All performance results based on 25000 numIters and jdk 1.4.2
60    *
61    * TEST TOTAL TIME(ms) - 1/1/06
62    *
63    * testMapping1 19562
64    * testMapping2 2859
65    * testMapping3 2782
66    * testMapping4 8391
67    * testMapping5 4985
68    *
69    * MHT Computer - 8/12/06
70    * #1 17015
71    * #2 1954
72    * #3 1890
73    * #4 5985
74    * #5 4062
75    *
76    * MHT Computer - 9/26/06 - After 2.3 release
77    * #1 19578
78    * #2 1937
79    * #3 1953
80    * #4 6734
81    * #5 4641
82    *
83    * MHT Computer - 10/1/06 - 2.4 release. After removing Reflection caching to resolve general CGLIB/Proxy issues
84    * #1 29313
85    * #2 2985
86    * #3 3130
87    * #4 9891
88    * #5 7656
89    *
90    * MHT Computer - 12/20/06 - 2.5 release. After adding code submitted for fixing recursive mapping infinite loop problem. Due to maintaining mappedFields variable in MappingProcessor. Is this ok or better way to do it? Not sure
91    *
92    * #1 31422
93    * #2 3485
94    * #3 3547
95    * #4 11656
96    * #5 8281
97    *
98    * MHT Computer - 1/26/07 - 2.5 release. After making misc perf improvements to improve test case #6
99    *
100    * #1 26047
101    * #2 3375
102    * #3 3469
103    * #4 11672
104    * #5 7516
105    * #6 45850
106    *
107    * MHT Computer - 2/1/07 - 2.5 release. Just prior to release of 2.5
108    *
109    * #1 26266
110    * #2 3094
111    * #3 3203
112    * #4 11297
113    * #5 7453
114    * #6 42312
115    *
116    */

117
118   public void testMapping1() throws Exception JavaDoc {
119     // TestObject --> TestObjectPrime
120
log.debug("Begin timings...");
121     TestObject src = TestDataFactory.getInputGeneralMappingTestObject();
122     runGeneric(src, TestObjectPrime.class, 35000);
123   }
124
125   
126   public void testMapping2() throws Exception JavaDoc {
127     // SimpleObject --> SimpleObjectPrime
128
log.debug("Begin timings...");
129     SimpleObj src = (SimpleObj) TestDataFactory.getSimpleObj();
130     runGeneric(src, SimpleObjPrime.class, 3600);
131   }
132
133   public void testMapping3() throws Exception JavaDoc {
134     // SimpleObject --> SimpleObjectPrime2
135
log.debug("Begin timings...");
136     SimpleObj src = (SimpleObj) TestDataFactory.getSimpleObj();
137     runGeneric(src, SimpleObjPrime2.class, 3700);
138   }
139
140   public void testMapping4() throws Exception JavaDoc {
141     // AnotherSubClass --> AnotherSubClassPrime (Inheritance)
142
log.debug("Begin timings...");
143     AnotherSubClass src = TestDataFactory.getAnotherSubClass();
144     runGeneric(src, AnotherSubClassPrime.class, 12000);
145   }
146
147   public void testMapping5() throws Exception JavaDoc {
148     // SrcDeepObj --> DestDeepObj (Field Deep)
149
log.debug("Begin timings...");
150     SrcDeepObj src = TestDataFactory.getSrcDeepObj();
151     runGeneric(src, DestDeepObj.class, 9000);
152   }
153   
154   //1-2007: Test Case submitted by Dave B.
155
public void testMapping6() throws Exception JavaDoc {
156     // MyClassA --> MyClassB. Src object contains List with 500 String elements.
157
MyClassA src = TestDataFactory.getRandomMyClassA();
158     runGeneric(src, MyClassB.class, 50000);
159   }
160   
161
162   private void runGeneric(Object JavaDoc src, Class JavaDoc destClass, long maxTimeAllowed) throws Exception JavaDoc {
163     // warm up the mapper
164
mapper.map(src, destClass);
165
166     // perform x number of additional mappings
167
StopWatch timer = new StopWatch();
168     timer.start();
169     for (int i = 0; i < numIters; i++) {
170       mapper.map(src, destClass);
171     }
172     timer.stop();
173     log.debug("Total time for additional " + numIters + " mappings: " + timer.getTime() + " milliseconds");
174     log.debug("avg time for " + numIters + " mappings: " + (timer.getTime() / numIters) + " milliseconds");
175
176     if (timer.getTime() > maxTimeAllowed) {
177       log.error("Elapsed time exceeded max allowed: " + maxTimeAllowed + " Actual time: " + timer.getTime());
178     }
179   }
180   
181
182   public static void main(String JavaDoc[] args) {
183     junit.textui.TestRunner.run(PerformanceTest.class);
184   }
185
186   /*
187   public static void main(String[] args) throws Exception {
188     PerformanceTest pt = new PerformanceTest();
189     pt.setUp();
190     pt.testMapping6_Dozer();
191   }
192   */

193   
194 }
195
Popular Tags