Source Code Cross Referenced for TestClassPerformance.java in  » UML » MetaBoss » com » jamonapi » 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 » UML » MetaBoss » com.jamonapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * TestClassPerformance.java
003:         *
004:         * Created on September 22, 2002, 8:59 AM
005:         */
006:
007:        package com.jamonapi;
008:
009:        /**
010:         * Class used to test performance of JAMon.  It is only used for testing purposes.
011:         *
012:         * @author  steve souza
013:         */
014:        public class TestClassPerformance {
015:
016:            /** Creates a new instance of TestClassPerformance */
017:            public TestClassPerformance() {
018:                this (100000);
019:            }
020:
021:            private int testIterations;
022:
023:            public TestClassPerformance(int testIterations) {
024:                this .testIterations = testIterations;
025:            }
026:
027:            private Monitor testMon;
028:
029:            public void timingNoMonitor() throws Exception {
030:                // The null monitor has the best possible performance
031:                System.out
032:                        .println("\ntimingNoMonitor() - timing the old fashioned way with System.currentTimeMillis() (i.e.no monitors)");
033:                System.out.println("System.currentTimeMillis() - startTime");
034:                long startTime = 0;
035:
036:                // note the assignment to startTime is meaningless.  The calculation for elapsed time would really be
037:                // as follows, however being as most implementations of this timing method would not assign the results
038:                // to an endTime variable, I thought it would be a better comparison to also leave it out in the performance
039:                // test.
040:                //  startTime = System.currentTimeMillis();
041:                //  endTime = System.currentTimeMillis() - startTime;
042:                for (int i = 0; i < testIterations; i++) {
043:                    startTime = System.currentTimeMillis()
044:                            - System.currentTimeMillis() - startTime;
045:                }
046:            }
047:
048:            public void basicTimingMonitor() throws Exception {
049:                // The null monitor has the best possible performance
050:                System.out
051:                        .println("\nbasicTimingMonitor() - this is the most lightweight of the Monitors");
052:                System.out
053:                        .println("\tBasicTimingMonitor mon=new BasicTimingMonitor();");
054:                System.out.println("\tmon.start()");
055:                System.out.println("\tmon.stop()");
056:                BasicTimingMonitor mon = new BasicTimingMonitor();
057:
058:                for (int i = 0; i < testIterations; i++) {
059:                    mon.start();
060:                    mon.stop();
061:                }
062:            }
063:
064:            public void nullMonitor() throws Exception {
065:                // The null monitor has the best possible performance, however it doesn't do anything so is only appropriate when monitoring 
066:                // is disabled.
067:                System.out
068:                        .println("\nNullMonitor() - Factory disabled so a NullMonitor is returned");
069:                System.out.println("\tMonitorFactory.setEnabled(false);");
070:                System.out.println("\tMonitor mon=MonitorFactory.start();");
071:                System.out.println("\tmon.stop()");
072:
073:                MonitorFactory.setEnabled(false);
074:
075:                for (int i = 0; i < testIterations; i++) {
076:                    testMon = MonitorFactory.start();
077:                    testMon.stop();
078:                }
079:
080:                MonitorFactory.setEnabled(true);
081:            }
082:
083:            public void nullMonitor2() throws Exception {
084:                // The null monitor has the best possible performance
085:                System.out
086:                        .println("\nNullMonitor2() - Factory disabled so a NullMonitor is returned");
087:                System.out.println("\tMonitorFactory.setEnabled(false);");
088:                System.out
089:                        .println("\tMonitor mon=MonitorFactory.start('pages.admin');");
090:                System.out.println("\tmon.stop()");
091:
092:                MonitorFactory.setEnabled(false);
093:
094:                for (int i = 0; i < testIterations; i++) {
095:                    testMon = MonitorFactory.start("pages.admin");
096:                    testMon.stop();
097:                }
098:
099:                MonitorFactory.setEnabled(true);
100:            }
101:
102:            public void factoryBasicMonitor() throws Exception {
103:                System.out.println("\nbasic Factory TimingMonitor()");
104:                System.out.println("\tMonitor mon=MonitorFactory.start();");
105:                System.out.println("\tmon.stop();");
106:
107:                //testMon=new TimingMonitor();  the following has the same performance characteristics but you also
108:                // have the added option of disabling the service and returning a null monitor
109:                for (int i = 0; i < testIterations; i++) {
110:                    testMon = MonitorFactory.start();
111:                    testMon.stop();
112:                }
113:
114:            }
115:
116:            public void factoryMonitor() throws Exception {
117:                System.out
118:                        .println("\nFull Factory TimingMonitor()- uses cached version so doesn't create child monitors");
119:                System.out
120:                        .println("\tMonitor mon=MonitorFactory.start('pages.admin');");
121:                System.out.println("\tmon.stop();");
122:
123:                for (int i = 0; i < testIterations; i++) {
124:                    testMon = MonitorFactory.start("pages.admin");
125:                    testMon.stop();
126:                }
127:
128:                System.out.println(testMon);
129:
130:            }
131:
132:            public void debugFactoryMonitor() throws Exception {
133:                System.out
134:                        .println("\nFull Factory TimingMonitor() using debug factory - uses cached version so doesn't create child monitors");
135:                System.out
136:                        .println("\tMonitor mon=MonitorFactory.getDebugFactory().start('pages.admin');");
137:                System.out.println("\tmon.stop();");
138:
139:                for (int i = 0; i < testIterations; i++) {
140:                    testMon = MonitorFactory.getDebugFactory().start(
141:                            "pages.admin"); // not executed if debug disabled.
142:                    testMon.stop();
143:                }
144:
145:                System.out.println(testMon);
146:
147:            }
148:
149:            private static void log(Object obj) {
150:                System.out.println("It took " + obj);
151:            }
152:
153:            /** Test class for performance numbers of JAMon.  You can execute the test code in the following 2 ways:
154:             *
155:             *  To execute with the default number of iterations (currently 100,000).  This takes about .5 seconds on my Pentium IV.
156:             *  java -cp JAMon.jar com.jamonapi.TestClassPerformance
157:             *
158:             *  To execute with a different number of iterations pass the number after the class name.
159:             *  java -cp JAMon.jar com.jamonapi.TestClassPerformance 500000
160:             **/
161:            public static void main(String[] args) throws Exception {
162:                TestClassPerformance test;
163:
164:                if (args.length == 0)
165:                    test = new TestClassPerformance();
166:                else {
167:                    int testIterations = Integer.parseInt(args[0]);
168:                    test = new TestClassPerformance(testIterations);
169:                }
170:
171:                System.out.println("\n***** Performance Tests:");
172:                System.out.println("All performance code loops "
173:                        + test.testIterations + " times");
174:
175:                Monitor totalTime, timingMon;
176:
177:                totalTime = MonitorFactory.start();
178:                timingMon = MonitorFactory.start();
179:                test.timingNoMonitor();
180:                log(timingMon.stop());
181:
182:                timingMon = MonitorFactory.start();
183:                test.basicTimingMonitor();
184:                log(timingMon.stop());
185:
186:                timingMon = MonitorFactory.start();
187:                test.nullMonitor();
188:                log(timingMon.stop());
189:
190:                timingMon = MonitorFactory.start();
191:                test.nullMonitor2();
192:                log(timingMon.stop());
193:
194:                timingMon = MonitorFactory.start();
195:                test.factoryBasicMonitor();
196:                log(timingMon.stop());
197:
198:                timingMon = MonitorFactory.start();
199:                test.debugFactoryMonitor();
200:                log(timingMon.stop());
201:
202:                timingMon = MonitorFactory.start();
203:                test.factoryMonitor();
204:                log(timingMon.stop());
205:
206:                System.out
207:                        .println("\nExecuting full factory monitors a second time.  The second time reflects performance characteristics more accurately");
208:
209:                timingMon = MonitorFactory.start();
210:                test.debugFactoryMonitor();
211:                log(timingMon.stop());
212:
213:                timingMon = MonitorFactory.start();
214:                test.factoryMonitor();
215:                log(timingMon.stop());
216:
217:                System.out
218:                        .println("\n***** Total time for performance tests were: "
219:                                + totalTime.stop());
220:
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.