1 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 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 { 50 super.setUp(); 51 if (mapper == null) { 52 mapper = getNewMapper(new String [] { "dozerBeanMapping.xml" }); 53 } 54 } 55 56 117 118 public void testMapping1() throws Exception { 119 log.debug("Begin timings..."); 121 TestObject src = TestDataFactory.getInputGeneralMappingTestObject(); 122 runGeneric(src, TestObjectPrime.class, 35000); 123 } 124 125 126 public void testMapping2() throws Exception { 127 log.debug("Begin timings..."); 129 SimpleObj src = (SimpleObj) TestDataFactory.getSimpleObj(); 130 runGeneric(src, SimpleObjPrime.class, 3600); 131 } 132 133 public void testMapping3() throws Exception { 134 log.debug("Begin timings..."); 136 SimpleObj src = (SimpleObj) TestDataFactory.getSimpleObj(); 137 runGeneric(src, SimpleObjPrime2.class, 3700); 138 } 139 140 public void testMapping4() throws Exception { 141 log.debug("Begin timings..."); 143 AnotherSubClass src = TestDataFactory.getAnotherSubClass(); 144 runGeneric(src, AnotherSubClassPrime.class, 12000); 145 } 146 147 public void testMapping5() throws Exception { 148 log.debug("Begin timings..."); 150 SrcDeepObj src = TestDataFactory.getSrcDeepObj(); 151 runGeneric(src, DestDeepObj.class, 9000); 152 } 153 154 public void testMapping6() throws Exception { 156 MyClassA src = TestDataFactory.getRandomMyClassA(); 158 runGeneric(src, MyClassB.class, 50000); 159 } 160 161 162 private void runGeneric(Object src, Class destClass, long maxTimeAllowed) throws Exception { 163 mapper.map(src, destClass); 165 166 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 [] args) { 183 junit.textui.TestRunner.run(PerformanceTest.class); 184 } 185 186 193 194 } 195 | Popular Tags |