1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.beanutils2;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.junit.jupiter.api.AfterEach;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30 public class PropertyUtilsBenchCase {
31
32
33 private long counter = 100000;
34
35
36 private DynaClass dynaClass;
37
38
39 private BenchBean inBean;
40 private DynaBean inDyna;
41 private Map<String, Object> inMap;
42
43
44 private BenchBean outBean;
45 private DynaBean outDyna;
46
47
48 private PropertyUtilsBean pu;
49
50
51
52
53 @BeforeEach
54 public void setUp() throws Exception {
55
56
57 final String prop = System.getProperty("counter");
58 if (prop != null) {
59 counter = Long.parseLong(prop);
60 }
61
62
63 dynaClass = new BasicDynaClass("BenchDynaClass", null,
64 new DynaProperty[] { new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("byteProperty", Byte.TYPE),
65 new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE),
66 new DynaProperty("intProperty", Integer.TYPE), new DynaProperty("longProperty", Long.TYPE),
67 new DynaProperty("shortProperty", Short.TYPE), new DynaProperty("stringProperty", String.class), });
68
69
70 inBean = new BenchBean();
71 inMap = new HashMap<>();
72 inMap.put("booleanProperty", Boolean.valueOf(inBean.getBooleanProperty()));
73 inMap.put("byteProperty", Byte.valueOf(inBean.getByteProperty()));
74 inMap.put("doubleProperty", Double.valueOf(inBean.getDoubleProperty()));
75 inMap.put("floatProperty", Float.valueOf(inBean.getFloatProperty()));
76 inMap.put("intProperty", Integer.valueOf(inBean.getIntProperty()));
77 inMap.put("longProperty", Long.valueOf(inBean.getLongProperty()));
78 inMap.put("shortProperty", Short.valueOf(inBean.getShortProperty()));
79 inMap.put("stringProperty", inBean.getStringProperty());
80 inDyna = dynaClass.newInstance();
81 for (final Map.Entry<String, Object> e : inMap.entrySet()) {
82 inDyna.set(e.getKey(), e.getValue());
83 }
84
85
86 outBean = new BenchBean();
87 outDyna = dynaClass.newInstance();
88 inDyna = dynaClass.newInstance();
89 for (final Map.Entry<String, Object> e : inMap.entrySet()) {
90 outDyna.set(e.getKey(), e.getValue());
91 }
92
93
94 pu = PropertyUtilsBean.getInstance();
95
96 }
97
98
99
100
101 @AfterEach
102 public void tearDown() {
103
104 dynaClass = null;
105 inBean = null;
106 inDyna = null;
107 inMap = null;
108 outBean = null;
109 outDyna = null;
110 pu = null;
111
112 }
113
114
115 @Test
116 public void testCopyPropertiesBean() throws Exception {
117
118 long startMillis;
119 long stopMillis;
120
121
122 for (long i = 0; i < counter; i++) {
123 pu.copyProperties(outBean, inBean);
124 }
125 startMillis = System.currentTimeMillis();
126 for (long i = 0; i < counter; i++) {
127 pu.copyProperties(outBean, inBean);
128 }
129 stopMillis = System.currentTimeMillis();
130 System.err.println("PU.copyProperties(bean,bean), count=" + counter + ", time=" + (stopMillis - startMillis));
131
132
133 for (long i = 0; i < counter; i++) {
134 pu.copyProperties(outDyna, inBean);
135 }
136 startMillis = System.currentTimeMillis();
137 for (long i = 0; i < counter; i++) {
138 pu.copyProperties(outDyna, inBean);
139 }
140 stopMillis = System.currentTimeMillis();
141 System.err.println("PU.copyProperties(dyna,bean), count=" + counter + ", time=" + (stopMillis - startMillis));
142
143 }
144
145
146 @Test
147 public void testCopyPropertiesDyna() throws Exception {
148
149 long startMillis;
150 long stopMillis;
151
152
153 for (long i = 0; i < counter; i++) {
154 pu.copyProperties(outBean, inDyna);
155 }
156 startMillis = System.currentTimeMillis();
157 for (long i = 0; i < counter; i++) {
158 pu.copyProperties(outBean, inDyna);
159 }
160 stopMillis = System.currentTimeMillis();
161 System.err.println("PU.copyProperties(bean,dyna), count=" + counter + ", time=" + (stopMillis - startMillis));
162
163
164 for (long i = 0; i < counter; i++) {
165 pu.copyProperties(outDyna, inDyna);
166 }
167 startMillis = System.currentTimeMillis();
168 for (long i = 0; i < counter; i++) {
169 pu.copyProperties(outDyna, inDyna);
170 }
171 stopMillis = System.currentTimeMillis();
172 System.err.println("PU.copyProperties(dyna,dyna), count=" + counter + ", time=" + (stopMillis - startMillis));
173
174 }
175
176
177 @Test
178 public void testCopyPropertiesMap() throws Exception {
179
180 long startMillis;
181 long stopMillis;
182
183
184 for (long i = 0; i < counter; i++) {
185 pu.copyProperties(outBean, inMap);
186 }
187 startMillis = System.currentTimeMillis();
188 for (long i = 0; i < counter; i++) {
189 pu.copyProperties(outBean, inMap);
190 }
191 stopMillis = System.currentTimeMillis();
192 System.err.println("PU.copyProperties(bean, map), count=" + counter + ", time=" + (stopMillis - startMillis));
193
194
195 for (long i = 0; i < counter; i++) {
196 pu.copyProperties(outDyna, inMap);
197 }
198 startMillis = System.currentTimeMillis();
199 for (long i = 0; i < counter; i++) {
200 pu.copyProperties(outDyna, inMap);
201 }
202 stopMillis = System.currentTimeMillis();
203 System.err.println("PU.copyProperties(dyna, map), count=" + counter + ", time=" + (stopMillis - startMillis));
204
205 }
206
207 }