Source Code Cross Referenced for RenderingBenchmarks.java in  » Database-Client » prefuse » test » 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 Client » prefuse » test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test;
002:
003:        import java.awt.Color;
004:        import java.awt.Dimension;
005:        import java.awt.Font;
006:        import java.awt.Graphics;
007:        import java.awt.Graphics2D;
008:        import java.awt.RenderingHints;
009:        import java.awt.Toolkit;
010:        import java.awt.font.GlyphVector;
011:        import java.awt.geom.Line2D;
012:        import java.awt.geom.Rectangle2D;
013:        import java.awt.geom.RoundRectangle2D;
014:        import java.util.logging.Logger;
015:
016:        import javax.swing.JComponent;
017:        import javax.swing.JFrame;
018:
019:        /**
020:         * RenderingBenchmarks
021:         * 
022:         * @author <a href="http://jheer.org">jeffrey heer</a>
023:         */
024:        public class RenderingBenchmarks extends JComponent {
025:
026:            private static final Logger s_logger = Logger
027:                    .getLogger(RenderingBenchmarks.class.getName());
028:
029:            private StringBuffer sbuf = new StringBuffer();
030:            private String testSuite;
031:            private String curTest;
032:            private int numItems;
033:            private long timein;
034:            private int fps = 20;
035:
036:            public RenderingBenchmarks() {
037:                this .setPreferredSize(new Dimension(500, 500));
038:            }
039:
040:            private void startTest(String name, int numItems) {
041:                if (curTest != null)
042:                    throw new IllegalStateException("In the middle of a test!");
043:                this .curTest = name;
044:                this .numItems = numItems;
045:                Toolkit tk = Toolkit.getDefaultToolkit();
046:                tk.sync();
047:                this .timein = System.currentTimeMillis();
048:            }
049:
050:            private void endTest(boolean print) {
051:                if (print) {
052:                    long t = System.currentTimeMillis() - timein;
053:                    double pps = 1000 * ((double) numItems) / t;
054:                    double ppf = pps / fps;
055:                    sbuf.append(curTest).append(" ").append(
056:                            curTest.length() > 14 ? "\t" : "\t\t").append(
057:                            numItems).append(" \t").append(t / 1000.0).append(
058:                            "s\t").append(((int) (pps * 100)) / 100.0).append(
059:                            " pr/s\t").append(((int) (ppf * 100)) / 100.0)
060:                            .append(" pr/fr").append('\n');
061:                }
062:                curTest = null;
063:            }
064:
065:            public void printHeader() {
066:                sbuf
067:                        .append("PRIMITIVE\t\tCOUNT\tTIME\tPRIMITIVES/SEC\tPRIMITIVES/FRAME @ ");
068:                sbuf.append(fps).append("fps").append('\n');
069:            }
070:
071:            public void paintComponent(Graphics g) {
072:                Graphics2D g2 = (Graphics2D) g;
073:
074:                int x = 0, y = 0, w = 100, h = 100, c = 10;
075:                float xf = 0f, yf = 0f, wf = 100f, hf = 100f, cf = 10f;
076:                int n;
077:
078:                g2.setColor(Color.BLACK);
079:                boolean print = false;
080:
081:                for (int j = 0; j < 3; ++j, print = true) {
082:
083:                    if (j == 1) {
084:                        print = true;
085:                        testSuite = "NORMAL";
086:                        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
087:                                RenderingHints.VALUE_ANTIALIAS_OFF);
088:                    } else if (j == 2) {
089:                        testSuite = "ANTI-ALIASING";
090:                        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
091:                                RenderingHints.VALUE_ANTIALIAS_ON);
092:                    }
093:
094:                    if (print) {
095:                        printHeader();
096:                    }
097:
098:                    // lines-direct
099:                    n = 10000;
100:                    startTest("lines-direct", n);
101:                    for (int i = 0; i < n; ++i) {
102:                        g2.drawLine(x, y, w, h);
103:                    }
104:                    endTest(print);
105:
106:                    // lines-shape
107:                    n = 10000;
108:                    Line2D line = new Line2D.Float(xf, yf, wf, hf);
109:                    startTest("lines-shape", n);
110:                    for (int i = 0; i < n; ++i) {
111:                        g2.draw(line);
112:                    }
113:                    line = null;
114:                    endTest(print);
115:
116:                    // rect-direct-draw
117:                    n = 10000;
118:                    startTest("rect-direct-draw", n);
119:                    for (int i = 0; i < n; ++i) {
120:                        g2.drawRect(x, y, w, h);
121:                    }
122:                    endTest(print);
123:
124:                    // rect-shape-draw
125:                    n = 10000;
126:                    Rectangle2D rect = new Rectangle2D.Float(xf, yf, wf, hf);
127:                    startTest("rect-shape-draw", n);
128:                    for (int i = 0; i < n; ++i) {
129:                        g2.draw(rect);
130:                    }
131:                    rect = null;
132:                    endTest(print);
133:
134:                    // rect-direct-fill
135:                    n = 10000;
136:                    startTest("rect-direct-fill", n);
137:                    for (int i = 0; i < n; ++i) {
138:                        g2.fillRect(x, y, w, h);
139:                    }
140:                    endTest(print);
141:
142:                    // rect-shape-fill
143:                    rect = new Rectangle2D.Float(xf, yf, wf, hf);
144:                    startTest("rect-shape-fill", n);
145:                    for (int i = 0; i < n; ++i) {
146:                        g2.fill(rect);
147:                    }
148:                    rect = null;
149:                    endTest(print);
150:
151:                    // rrect-direct-draw
152:                    startTest("rrect-direct-draw", n);
153:                    for (int i = 0; i < n; ++i) {
154:                        g2.drawRoundRect(x, y, w, h, c, c);
155:                    }
156:                    endTest(print);
157:
158:                    // rrect-shape-draw
159:                    RoundRectangle2D rrect = new RoundRectangle2D.Float(xf, yf,
160:                            wf, hf, cf, cf);
161:                    startTest("rrect-shape-draw", n);
162:                    for (int i = 0; i < n; ++i) {
163:                        g2.draw(rrect);
164:                    }
165:                    rrect = null;
166:                    endTest(print);
167:
168:                    // rrect-direct-fill
169:                    startTest("rrect-direct-fill", n);
170:                    for (int i = 0; i < n; ++i) {
171:                        g2.fillRoundRect(x, y, w, h, c, c);
172:                    }
173:                    endTest(print);
174:
175:                    // rrect-shape-fill
176:                    rrect = new RoundRectangle2D.Float(xf, yf, wf, hf, cf, cf);
177:                    startTest("rrect-shape-fill", n);
178:                    for (int i = 0; i < n; ++i) {
179:                        g2.fill(rrect);
180:                    }
181:                    rrect = null;
182:                    endTest(print);
183:
184:                    // text-direct-int
185:                    String text = "This is some sample text.";
186:                    startTest("text-direct-int", n);
187:                    for (int i = 0; i < n; ++i) {
188:                        g2.drawString(text, x + 2, h / 2);
189:                    }
190:                    endTest(print);
191:
192:                    // text-direct-float
193:                    startTest("text-direct-float", n);
194:                    for (int i = 0; i < n; ++i) {
195:                        g2.drawString(text, xf + 2, hf / 2);
196:                    }
197:                    endTest(print);
198:
199:                    // text-glyph-vector
200:                    Font f = g2.getFont();
201:                    GlyphVector gvec = f.createGlyphVector(g2
202:                            .getFontRenderContext(), text);
203:                    startTest("text-glyph-vector", n);
204:                    for (int i = 0; i < n; ++i) {
205:                        g2.drawGlyphVector(gvec, xf + 2, hf / 2);
206:                    }
207:                    endTest(print);
208:
209:                    if (print) {
210:                        s_logger.info("Rendering Benchmarks: " + testSuite
211:                                + '\n' + sbuf.toString());
212:                        sbuf.replace(0, sbuf.length(), "");
213:                    }
214:                }
215:                System.exit(0);
216:            }
217:
218:            public static void main(String[] args) {
219:                JFrame f = new JFrame("Rendering Test");
220:                f.setSize(500, 500);
221:                f.getContentPane().add(new RenderingBenchmarks());
222:                f.pack();
223:                f.setVisible(true);
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.