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