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


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