Source Code Cross Referenced for Performance.java in  » Database-ORM » MMBase » org » mmbase » servlet » 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 » Database ORM » MMBase » org.mmbase.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  This software is OSI Certified Open Source Software.
003:         *  OSI Certified is a certification mark of the Open Source Initiative.
004:         *  The license (Mozilla version 1.0) can be read at the MMBase site.
005:         *  See http://www.MMBase.org/license
006:         */
007:        package org.mmbase.servlet;
008:
009:        import java.io.IOException;
010:        import java.io.PrintStream;
011:        import java.util.Date;
012:        import javax.servlet.ServletException;
013:        import javax.servlet.http.HttpServletRequest;
014:        import javax.servlet.http.HttpServletResponse;
015:
016:        /**
017:         * Performance Servlet is used as a basic Servlet to test whether the installation of succeeded.
018:         * It also does a very basic test to measure how fast the JVM is.
019:         *
020:         * @author  vpro
021:         * @version $Id: Performance.java,v 1.2 2007/02/10 16:22:37 nklasens Exp $
022:         */
023:        public class Performance extends BridgeServlet {
024:
025:            public static final long INT_LOOP = 20000000;
026:            public static final long STRING_LOOP = 2500000;
027:            public static final long METHOD_LOOP = 10000000;
028:            public static final String TEST_STRING = "test";
029:
030:            /**
031:             * @javadoc
032:             */
033:            public void init() throws ServletException {
034:                super .init();
035:            }
036:
037:            /**
038:             * Called by the server when a request is done.
039:             * @javadoc
040:             */
041:            public synchronized void doGet(HttpServletRequest req,
042:                    HttpServletResponse res) throws ServletException,
043:                    IOException {
044:                // Open	a output stream so you can write to the client
045:                PrintStream out = new PrintStream(res.getOutputStream());
046:
047:                // Set the content type of this request
048:                res.setContentType("text/html");
049:
050:                // Write header to client
051:                //res.writeHeaders();
052:
053:                // WRITE MESSAGE TO CLIENT
054:                out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
055:                out
056:                        .println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\" >");
057:                out
058:                        .println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">");
059:                out.println("<head><title>Performance</title></head>");
060:                out.println("<body>");
061:                out.println("<h1>Performance Servlet</h1>");
062:                out.println("<p>" + getServletInfo() + "</p>");
063:                long time = intloop();
064:                out.println("<p><strong>Performance Test (simple loop "
065:                        + INT_LOOP + " times) </strong><br />");
066:                out.println("takes " + time + "ms, "
067:                        + (((double) time) / INT_LOOP) + " ms/loop </p>");
068:                time = string();
069:                out.println("<p><strong>Performance Test (compare '"
070:                        + TEST_STRING + "' " + STRING_LOOP
071:                        + " times) </strong><br />");
072:                out.println("takes " + time + "ms, "
073:                        + (((double) time) / STRING_LOOP) + " ms/loop </p>");
074:
075:                out
076:                        .println("<p><strong>Performance Test (loop through the provided stub method "
077:                                + METHOD_LOOP + " times) </strong><br />");
078:                out.println("takes " + time + "ms, "
079:                        + (((double) time) / METHOD_LOOP) + " ms/loop </p>");
080:                out.println("</body>");
081:                out.println("</html>");
082:            }
083:
084:            /**
085:             * @javadoc
086:             */
087:            private long intloop() {
088:                long begin = new Date().getTime();
089:                for (int i = 0; i < 20000000; i++) {
090:                    ;
091:                }
092:                long end = new Date().getTime();
093:                return end - begin;
094:            }
095:
096:            /**
097:             * @javadoc
098:             */
099:            private long string() {
100:                long begin = new Date().getTime();
101:                String test = TEST_STRING;
102:                for (int i = 0; i < 2500000; i++) {
103:                    test.equals(TEST_STRING);
104:                }
105:                long end = new Date().getTime();
106:                return end - begin;
107:            }
108:
109:            /**
110:             * @javadoc
111:             */
112:            protected void stub() {
113:            }
114:
115:            /**
116:             * Info method, provides the user/server with some basic info on this Servlet
117:             * @return a descriptive text
118:             */
119:            public String getServletInfo() {
120:                return ("Performance tester, for JIT and other things");
121:            }
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.