1 16 17 18 package org.apache.commons.beanutils; 19 20 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import junit.framework.TestCase; 25 import junit.framework.Test; 26 import junit.framework.TestSuite; 27 28 29 32 33 public class PropertyUtilsBenchCase extends TestCase { 34 35 36 38 39 44 public PropertyUtilsBenchCase(String name) { 45 46 super(name); 47 48 } 49 50 51 53 54 private long counter = 100000; 56 57 private DynaClass dynaClass = null; 59 60 private BenchBean inBean = null; 62 private DynaBean inDyna = null; 63 private Map inMap = null; 64 65 private BenchBean outBean = null; 67 private DynaBean outDyna = null; 68 69 private PropertyUtilsBean pu = null; 71 72 73 75 76 79 public void setUp() throws Exception { 80 81 String prop = System.getProperty("counter"); 83 if (prop != null) { 84 counter = Long.parseLong(prop); 85 } 86 87 dynaClass = new BasicDynaClass 89 ("BenchDynaClass", null, 90 new DynaProperty[]{ 91 new DynaProperty("booleanProperty", Boolean.TYPE), 92 new DynaProperty("byteProperty", Byte.TYPE), 93 new DynaProperty("doubleProperty", Double.TYPE), 94 new DynaProperty("floatProperty", Float.TYPE), 95 new DynaProperty("intProperty", Integer.TYPE), 96 new DynaProperty("longProperty", Long.TYPE), 97 new DynaProperty("shortProperty", Short.TYPE), 98 new DynaProperty("stringProperty", String .class), 99 }); 100 101 inBean = new BenchBean(); 103 inMap = new HashMap (); 104 inMap.put("booleanProperty", new Boolean (inBean.getBooleanProperty())); 105 inMap.put("byteProperty", new Byte (inBean.getByteProperty())); 106 inMap.put("doubleProperty", new Double (inBean.getDoubleProperty())); 107 inMap.put("floatProperty", new Float (inBean.getFloatProperty())); 108 inMap.put("intProperty", new Integer (inBean.getIntProperty())); 109 inMap.put("longProperty", new Long (inBean.getLongProperty())); 110 inMap.put("shortProperty", new Short (inBean.getShortProperty())); 111 inMap.put("stringProperty", inBean.getStringProperty()); 112 inDyna = dynaClass.newInstance(); 113 Iterator inKeys = inMap.keySet().iterator(); 114 while (inKeys.hasNext()) { 115 String inKey = (String ) inKeys.next(); 116 inDyna.set(inKey, inMap.get(inKey)); 117 } 118 119 outBean = new BenchBean(); 121 outDyna = dynaClass.newInstance(); 122 Iterator outKeys = inMap.keySet().iterator(); 123 while (outKeys.hasNext()) { 124 String outKey = (String ) outKeys.next(); 125 outDyna.set(outKey, inMap.get(outKey)); 126 } 127 128 pu = PropertyUtilsBean.getInstance(); 130 131 } 132 133 134 137 public static Test suite() { 138 139 return (new TestSuite(PropertyUtilsBenchCase.class)); 140 141 } 142 143 144 147 public void tearDown() { 148 149 dynaClass = null; 150 inBean = null; 151 inDyna = null; 152 inMap = null; 153 outBean = null; 154 outDyna = null; 155 pu = null; 156 157 } 158 159 160 161 163 164 public void testCopyPropertiesBean() throws Exception { 166 167 long start; 168 long stop; 169 170 for (long i = 0; i < counter; i++) { 172 pu.copyProperties(outBean, inBean); 173 } 174 start = System.currentTimeMillis(); 175 for (long i = 0; i < counter; i++) { 176 pu.copyProperties(outBean, inBean); 177 } 178 stop = System.currentTimeMillis(); 179 System.err.println("PU.copyProperties(bean,bean), count=" + counter + 180 ", time=" + (stop - start)); 181 182 for (long i = 0; i < counter; i++) { 184 pu.copyProperties(outDyna, inBean); 185 } 186 start = System.currentTimeMillis(); 187 for (long i = 0; i < counter; i++) { 188 pu.copyProperties(outDyna, inBean); 189 } 190 stop = System.currentTimeMillis(); 191 System.err.println("PU.copyProperties(dyna,bean), count=" + counter + 192 ", time=" + (stop - start)); 193 194 } 195 196 197 public void testCopyPropertiesDyna() throws Exception { 199 200 long start; 201 long stop; 202 203 for (long i = 0; i < counter; i++) { 205 pu.copyProperties(outBean, inDyna); 206 } 207 start = System.currentTimeMillis(); 208 for (long i = 0; i < counter; i++) { 209 pu.copyProperties(outBean, inDyna); 210 } 211 stop = System.currentTimeMillis(); 212 System.err.println("PU.copyProperties(bean,dyna), count=" + counter + 213 ", time=" + (stop - start)); 214 215 for (long i = 0; i < counter; i++) { 217 pu.copyProperties(outDyna, inDyna); 218 } 219 start = System.currentTimeMillis(); 220 for (long i = 0; i < counter; i++) { 221 pu.copyProperties(outDyna, inDyna); 222 } 223 stop = System.currentTimeMillis(); 224 System.err.println("PU.copyProperties(dyna,dyna), count=" + counter + 225 ", time=" + (stop - start)); 226 227 } 228 229 230 public void testCopyPropertiesMap() throws Exception { 232 233 long start; 234 long stop; 235 236 for (long i = 0; i < counter; i++) { 238 pu.copyProperties(outBean, inMap); 239 } 240 start = System.currentTimeMillis(); 241 for (long i = 0; i < counter; i++) { 242 pu.copyProperties(outBean, inMap); 243 } 244 stop = System.currentTimeMillis(); 245 System.err.println("PU.copyProperties(bean, map), count=" + counter + 246 ", time=" + (stop - start)); 247 248 for (long i = 0; i < counter; i++) { 250 pu.copyProperties(outDyna, inMap); 251 } 252 start = System.currentTimeMillis(); 253 for (long i = 0; i < counter; i++) { 254 pu.copyProperties(outDyna, inMap); 255 } 256 stop = System.currentTimeMillis(); 257 System.err.println("PU.copyProperties(dyna, map), count=" + counter + 258 ", time=" + (stop - start)); 259 260 } 261 262 263 265 266 } 267 | Popular Tags |