Source Code Cross Referenced for BeanUtilsBenchCase.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons beanutils 1.8.0 BETA src » org.apache.commons.beanutils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.beanutils;
019:
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.Map;
023:        import junit.framework.TestCase;
024:        import junit.framework.Test;
025:        import junit.framework.TestSuite;
026:
027:        /**
028:         * JUnit Test Case containing microbenchmarks for BeanUtils.
029:         */
030:
031:        public class BeanUtilsBenchCase extends TestCase {
032:
033:            // ------------------------------------------------------------ Constructors
034:
035:            /**
036:             * Construct a new instance of this test case.
037:             *
038:             * @param name Name of the test case
039:             */
040:            public BeanUtilsBenchCase(String name) {
041:
042:                super (name);
043:
044:            }
045:
046:            // ------------------------------------------------------ Instance Variables
047:
048:            // Basic loop counter
049:            private long counter = 100000;
050:
051:            // DynaClass for inDyna and outDyna
052:            private DynaClass dynaClass = null;
053:
054:            // Input objects that have identical sets of properties and values.
055:            private BenchBean inBean = null;
056:            private DynaBean inDyna = null;
057:            private Map inMap = null; // Map of Objects requiring no conversion
058:            private Map inStrs = null; // Map of Strings requiring conversion
059:
060:            // Output objects that have identical sets of properties.
061:            private BenchBean outBean = null;
062:            private DynaBean outDyna = null;
063:
064:            // BeanUtilsBean instance to be used
065:            private BeanUtilsBean bu = null;
066:
067:            // ---------------------------------------------------- Overall Test Methods
068:
069:            /**
070:             * Set up instance variables required by this test case.
071:             */
072:            public void setUp() throws Exception {
073:
074:                // Set up loop counter (if property specified)
075:                String prop = System.getProperty("counter");
076:                if (prop != null) {
077:                    counter = Long.parseLong(prop);
078:                }
079:
080:                // Set up DynaClass for our DynaBean instances
081:                dynaClass = new BasicDynaClass(
082:                        "BenchDynaClass",
083:                        null,
084:                        new DynaProperty[] {
085:                                new DynaProperty("booleanProperty",
086:                                        Boolean.TYPE),
087:                                new DynaProperty("byteProperty", Byte.TYPE),
088:                                new DynaProperty("doubleProperty", Double.TYPE),
089:                                new DynaProperty("floatProperty", Float.TYPE),
090:                                new DynaProperty("intProperty", Integer.TYPE),
091:                                new DynaProperty("longProperty", Long.TYPE),
092:                                new DynaProperty("shortProperty", Short.TYPE),
093:                                new DynaProperty("stringProperty", String.class), });
094:
095:                // Create input instances
096:                inBean = new BenchBean();
097:                inMap = new HashMap();
098:                inMap.put("booleanProperty", new Boolean(inBean
099:                        .getBooleanProperty()));
100:                inMap.put("byteProperty", new Byte(inBean.getByteProperty()));
101:                inMap.put("doubleProperty", new Double(inBean
102:                        .getDoubleProperty()));
103:                inMap
104:                        .put("floatProperty", new Float(inBean
105:                                .getFloatProperty()));
106:                inMap.put("intProperty", new Integer(inBean.getIntProperty()));
107:                inMap.put("longProperty", new Long(inBean.getLongProperty()));
108:                inMap
109:                        .put("shortProperty", new Short(inBean
110:                                .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:                inStrs = new HashMap();
119:                inKeys = inMap.keySet().iterator();
120:                while (inKeys.hasNext()) {
121:                    String inKey = (String) inKeys.next();
122:                    inStrs.put(inKey, inMap.get(inKey).toString());
123:                }
124:
125:                // Create output instances
126:                outBean = new BenchBean();
127:                outDyna = dynaClass.newInstance();
128:                Iterator outKeys = inMap.keySet().iterator();
129:                while (outKeys.hasNext()) {
130:                    String outKey = (String) outKeys.next();
131:                    outDyna.set(outKey, inMap.get(outKey));
132:                }
133:
134:                // Set up BeanUtilsBean instance we will use
135:                bu = BeanUtilsBean.getInstance();
136:
137:            }
138:
139:            /**
140:             * Return the tests included in this test suite.
141:             */
142:            public static Test suite() {
143:
144:                return (new TestSuite(BeanUtilsBenchCase.class));
145:
146:            }
147:
148:            /**
149:             * Tear down instance variables required by this test case.
150:             */
151:            public void tearDown() {
152:
153:                dynaClass = null;
154:                inBean = null;
155:                inDyna = null;
156:                inMap = null;
157:                outBean = null;
158:                outDyna = null;
159:                bu = null;
160:
161:            }
162:
163:            // ------------------------------------------------- Individual Test Methods
164:
165:            // Time copyProperties() from a bean
166:            public void testCopyPropertiesBean() throws Exception {
167:
168:                long start;
169:                long stop;
170:
171:                // Bean->Bean
172:                for (long i = 0; i < counter; i++) {
173:                    bu.copyProperties(outBean, inBean);
174:                }
175:                start = System.currentTimeMillis();
176:                for (long i = 0; i < counter; i++) {
177:                    bu.copyProperties(outBean, inBean);
178:                }
179:                stop = System.currentTimeMillis();
180:                System.err.println("BU.copyProperties(bean,bean), count="
181:                        + counter + ", time=" + (stop - start));
182:
183:                // Bean->Dyna
184:                for (long i = 0; i < counter; i++) {
185:                    bu.copyProperties(outDyna, inBean);
186:                }
187:                start = System.currentTimeMillis();
188:                for (long i = 0; i < counter; i++) {
189:                    bu.copyProperties(outDyna, inBean);
190:                }
191:                stop = System.currentTimeMillis();
192:                System.err.println("BU.copyProperties(dyna,bean), count="
193:                        + counter + ", time=" + (stop - start));
194:
195:            }
196:
197:            // Time copyProperties() from a DynaBean
198:            public void testCopyPropertiesDyna() throws Exception {
199:
200:                long start;
201:                long stop;
202:
203:                // Dyna->Bean
204:                for (long i = 0; i < counter; i++) {
205:                    bu.copyProperties(outBean, inDyna);
206:                }
207:                start = System.currentTimeMillis();
208:                for (long i = 0; i < counter; i++) {
209:                    bu.copyProperties(outBean, inDyna);
210:                }
211:                stop = System.currentTimeMillis();
212:                System.err.println("BU.copyProperties(bean,dyna), count="
213:                        + counter + ", time=" + (stop - start));
214:
215:                // Dyna->Dyna
216:                for (long i = 0; i < counter; i++) {
217:                    bu.copyProperties(outDyna, inDyna);
218:                }
219:                start = System.currentTimeMillis();
220:                for (long i = 0; i < counter; i++) {
221:                    bu.copyProperties(outDyna, inDyna);
222:                }
223:                stop = System.currentTimeMillis();
224:                System.err.println("BU.copyProperties(dyna,dyna), count="
225:                        + counter + ", time=" + (stop - start));
226:
227:            }
228:
229:            // Time copyProperties() from a Map of Objects
230:            public void testCopyPropertiesMap() throws Exception {
231:
232:                long start;
233:                long stop;
234:
235:                // Map->Bean
236:                for (long i = 0; i < counter; i++) {
237:                    bu.copyProperties(outBean, inMap);
238:                }
239:                start = System.currentTimeMillis();
240:                for (long i = 0; i < counter; i++) {
241:                    bu.copyProperties(outBean, inMap);
242:                }
243:                stop = System.currentTimeMillis();
244:                System.err.println("BU.copyProperties(bean, map), count="
245:                        + counter + ", time=" + (stop - start));
246:
247:                // Map->Dyna
248:                for (long i = 0; i < counter; i++) {
249:                    bu.copyProperties(outDyna, inMap);
250:                }
251:                start = System.currentTimeMillis();
252:                for (long i = 0; i < counter; i++) {
253:                    bu.copyProperties(outDyna, inMap);
254:                }
255:                stop = System.currentTimeMillis();
256:                System.err.println("BU.copyProperties(dyna, map), count="
257:                        + counter + ", time=" + (stop - start));
258:
259:            }
260:
261:            // Time copyProperties() from a Map of Strings
262:            public void testCopyPropertiesStrs() throws Exception {
263:
264:                long start;
265:                long stop;
266:
267:                // Strs->Bean
268:                for (long i = 0; i < counter; i++) {
269:                    bu.copyProperties(outBean, inStrs);
270:                }
271:                start = System.currentTimeMillis();
272:                for (long i = 0; i < counter; i++) {
273:                    bu.copyProperties(outBean, inStrs);
274:                }
275:                stop = System.currentTimeMillis();
276:                System.err.println("BU.copyProperties(bean,strs), count="
277:                        + counter + ", time=" + (stop - start));
278:
279:                // Strs->Dyna
280:                for (long i = 0; i < counter; i++) {
281:                    bu.copyProperties(outDyna, inStrs);
282:                }
283:                start = System.currentTimeMillis();
284:                for (long i = 0; i < counter; i++) {
285:                    bu.copyProperties(outDyna, inStrs);
286:                }
287:                stop = System.currentTimeMillis();
288:                System.err.println("BU.copyProperties(dyna,strs), count="
289:                        + counter + ", time=" + (stop - start));
290:
291:            }
292:
293:            // Time populate() from a Map of Objects
294:            public void testPopulateMap() throws Exception {
295:
296:                long start;
297:                long stop;
298:
299:                // Map->Bean
300:                for (long i = 0; i < counter; i++) {
301:                    bu.populate(outBean, inMap);
302:                }
303:                start = System.currentTimeMillis();
304:                for (long i = 0; i < counter; i++) {
305:                    bu.populate(outBean, inMap);
306:                }
307:                stop = System.currentTimeMillis();
308:                System.err.println("BU.populate(bean, map), count=" + counter
309:                        + ", time=" + (stop - start));
310:
311:                // Map->Dyna
312:                for (long i = 0; i < counter; i++) {
313:                    bu.populate(outDyna, inMap);
314:                }
315:                start = System.currentTimeMillis();
316:                for (long i = 0; i < counter; i++) {
317:                    bu.populate(outDyna, inMap);
318:                }
319:                stop = System.currentTimeMillis();
320:                System.err.println("BU.populate(dyna, map), count=" + counter
321:                        + ", time=" + (stop - start));
322:
323:            }
324:
325:            // Time populate() from a Map of Strings
326:            // NOTE - This simulates what Struts does when processing form beans
327:            public void testPopulateStrs() throws Exception {
328:
329:                long start;
330:                long stop;
331:
332:                // Strs->Bean
333:                for (long i = 0; i < counter; i++) {
334:                    bu.populate(outBean, inStrs);
335:                }
336:                start = System.currentTimeMillis();
337:                for (long i = 0; i < counter; i++) {
338:                    bu.populate(outBean, inStrs);
339:                }
340:                stop = System.currentTimeMillis();
341:                System.err.println("BU.populate(bean,strs), count=" + counter
342:                        + ", time=" + (stop - start));
343:
344:                // Strs->Dyna
345:                for (long i = 0; i < counter; i++) {
346:                    bu.populate(outDyna, inStrs);
347:                }
348:                start = System.currentTimeMillis();
349:                for (long i = 0; i < counter; i++) {
350:                    bu.populate(outDyna, inStrs);
351:                }
352:                stop = System.currentTimeMillis();
353:                System.err.println("BU.populate(dyna,strs), count=" + counter
354:                        + ", time=" + (stop - start));
355:
356:            }
357:
358:            // --------------------------------------------------------- Support Methods
359:
360:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.