Source Code Cross Referenced for XmlFriendlyBenchmark.java in  » XML » xstream-1.3 » com » thoughtworks » xstream » benchmark » xmlfriendly » 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 » XML » xstream 1.3 » com.thoughtworks.xstream.benchmark.xmlfriendly 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2007 XStream Committers.
003:         * All rights reserved.
004:         *
005:         * The software in this package is published under the terms of the BSD
006:         * style license a copy of which has been included with this distribution in
007:         * the LICENSE.txt file.
008:         * 
009:         * Created on 13. September 2007 by Joerg Schaible
010:         */
011:        package com.thoughtworks.xstream.benchmark.xmlfriendly;
012:
013:        import com.thoughtworks.xstream.InitializationException;
014:        import com.thoughtworks.xstream.XStream;
015:        import com.thoughtworks.xstream.benchmark.reflection.targets.FieldReflection;
016:        import com.thoughtworks.xstream.benchmark.xmlfriendly.metric.CharacterCountMetric;
017:        import com.thoughtworks.xstream.benchmark.xmlfriendly.product.CombinedLookupAppender;
018:        import com.thoughtworks.xstream.benchmark.xmlfriendly.product.CombinedLookupReplacer;
019:        import com.thoughtworks.xstream.benchmark.xmlfriendly.product.IterativeAppender;
020:        import com.thoughtworks.xstream.benchmark.xmlfriendly.product.IterativeReplacer;
021:        import com.thoughtworks.xstream.benchmark.xmlfriendly.product.NoReplacer;
022:        import com.thoughtworks.xstream.benchmark.xmlfriendly.product.SeparateLookupReplacer;
023:        import com.thoughtworks.xstream.benchmark.xmlfriendly.product.XStream122Replacer;
024:        import com.thoughtworks.xstream.benchmark.xmlfriendly.target.Field_Reflection;
025:        import com.thoughtworks.xstream.benchmark.xmlfriendly.target.Field$Reflection;
026:        import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
027:        import com.thoughtworks.xstream.io.xml.XppDriver;
028:        import com.thoughtworks.xstream.tools.benchmark.Harness;
029:        import com.thoughtworks.xstream.tools.benchmark.Reporter;
030:        import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric;
031:        import com.thoughtworks.xstream.tools.benchmark.metrics.SerializationSpeedMetric;
032:        import com.thoughtworks.xstream.tools.benchmark.metrics.SizeMetric;
033:        import com.thoughtworks.xstream.tools.benchmark.reporters.HtmlReporter;
034:        import com.thoughtworks.xstream.tools.benchmark.reporters.MultiReporter;
035:        import com.thoughtworks.xstream.tools.benchmark.reporters.TextReporter;
036:
037:        import junit.framework.Test;
038:        import junit.framework.TestCase;
039:        import junit.framework.TestSuite;
040:
041:        import java.io.File;
042:        import java.io.FileWriter;
043:        import java.io.IOException;
044:        import java.lang.reflect.Constructor;
045:        import java.lang.reflect.InvocationTargetException;
046:
047:        /**
048:         * Main application to run harness for Reflection benchmark.
049:         * 
050:         * @author Jörg Schaible
051:         */
052:        public class XmlFriendlyBenchmark extends TestSuite {
053:
054:            public static class __ {
055:                public static class UnfriendlyClass {
056:                    String __a__$$a__;
057:                    String b__b__;
058:                    String __c__c;
059:
060:                    public boolean equals(Object obj) {
061:                        UnfriendlyClass other = (UnfriendlyClass) obj;
062:                        return __a__$$a__.equals(other.__a__$$a__)
063:                                && b__b__.equals(other.b__b__)
064:                                && __c__c.equals(other.__c__c);
065:                    }
066:
067:                }
068:            }
069:
070:            private static Class currentType;
071:
072:            public static class ReplacerTest extends TestCase {
073:
074:                private final Class type;
075:
076:                public ReplacerTest(String name) {
077:                    super (name);
078:                    type = currentType;
079:                }
080:
081:                public String getName() {
082:                    return type.getName() + ": " + super .getName();
083:                }
084:
085:                public void testReplacerWithDefaultReplacements() {
086:                    String xml = ""
087:                            + "<com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-_____-UnfriendlyClass>\n"
088:                            + "  <____a_____-_-a____>a</____a_____-_-a____>\n"
089:                            + "  <b____b____>b</b____b____>\n"
090:                            + "  <____c____c>c</____c____c>\n"
091:                            + "</com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-_____-UnfriendlyClass>";
092:                    performTest("_-", "__", getReference(), xml);
093:                }
094:
095:                public void testReplacerWithDollarReplacementOnly() {
096:                    String xml = ""
097:                            + "<com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-___-UnfriendlyClass>\n"
098:                            + "  <__a___-_-a__>a</__a___-_-a__>\n"
099:                            + "  <b__b__>b</b__b__>\n"
100:                            + "  <__c__c>c</__c__c>\n"
101:                            + "</com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-___-UnfriendlyClass>";
102:                    performTest("_-", "_", getReference(), xml);
103:                }
104:
105:                private void performTest(String dollar, String underscore,
106:                        __.UnfriendlyClass object, String xml) {
107:                    XStream xstream = createXStreamWithReplacer(dollar,
108:                            underscore);
109:                    assertEquals(xml, xstream.toXML(object));
110:                    assertEquals(object, xstream.fromXML(xml));
111:                }
112:
113:                private __.UnfriendlyClass getReference() {
114:                    __.UnfriendlyClass ref = new __.UnfriendlyClass();
115:                    ref.__a__$$a__ = "a";
116:                    ref.b__b__ = "b";
117:                    ref.__c__c = "c";
118:                    return ref;
119:                }
120:
121:                private XStream createXStreamWithReplacer(String dollar,
122:                        String underscore) {
123:                    Exception ex;
124:                    try {
125:                        Constructor constructor = type
126:                                .getConstructor(new Class[] { String.class,
127:                                        String.class, int.class });
128:                        XmlFriendlyReplacer replacer = (XmlFriendlyReplacer) constructor
129:                                .newInstance(new Object[] { dollar, underscore,
130:                                        new Integer(0) });
131:                        return new XStream(new XppDriver(replacer));
132:                    } catch (NoSuchMethodException e) {
133:                        ex = e;
134:                    } catch (InstantiationException e) {
135:                        ex = e;
136:                    } catch (IllegalAccessException e) {
137:                        ex = e;
138:                    } catch (InvocationTargetException e) {
139:                        ex = e;
140:                    }
141:                    throw new InitializationException(
142:                            "Cannot initialize XmlFriendlyReplacer", ex);
143:                }
144:            }
145:
146:            XmlFriendlyBenchmark() {
147:                addTestSuite(XStream122Replacer.XmlFriendlyReplacer.class);
148:                addTestSuite(CombinedLookupAppender.XmlFriendlyReplacer.class);
149:                addTestSuite(CombinedLookupReplacer.XmlFriendlyReplacer.class);
150:                addTestSuite(IterativeAppender.XmlFriendlyReplacer.class);
151:                addTestSuite(IterativeReplacer.XmlFriendlyReplacer.class);
152:                addTestSuite(SeparateLookupReplacer.XmlFriendlyReplacer.class);
153:            }
154:
155:            public void addTestSuite(Class replacerClass) {
156:                currentType = replacerClass;
157:                super .addTestSuite(ReplacerTest.class);
158:            }
159:
160:            public static Test suite() {
161:                // Ensure the different implementations work
162:                return new XmlFriendlyBenchmark();
163:            }
164:
165:            public static void main(String[] args) {
166:                new File("target/benchmarks").mkdirs();
167:
168:                Reporter[] reporters;
169:                try {
170:                    String basename = "target/benchmarks/xmlfriendly-"
171:                            + System.getProperty("user.name");
172:                    reporters = new Reporter[] {
173:                            new TextReporter(),
174:                            new TextReporter(new FileWriter(basename + ".txt")),
175:                            new HtmlReporter(new File(basename + ".html"),
176:                                    "XmlFriendlyReplacer Benchmark") };
177:                } catch (IOException e) {
178:                    throw new RuntimeException(e);
179:                }
180:
181:                Harness stats = new Harness();
182:                stats.addMetric(new SizeMetric());
183:                stats.addMetric(new CharacterCountMetric('$'));
184:                stats.addMetric(new CharacterCountMetric('_'));
185:                stats.addProduct(new NoReplacer());
186:                stats.addTarget(new FieldReflection());
187:                stats.addTarget(new Field_Reflection());
188:                stats.addTarget(new Field$Reflection());
189:                stats.run(new MultiReporter(reporters) {
190:
191:                    public void endBenchmark() {
192:                        // do nothing
193:                    }
194:
195:                });
196:
197:                Harness harness = new Harness();
198:                harness.addMetric(new SerializationSpeedMetric(50));
199:                harness.addMetric(new DeserializationSpeedMetric(50, false));
200:                harness.addProduct(new XStream122Replacer());
201:                harness.addProduct(new CombinedLookupAppender(0));
202:                harness.addProduct(new CombinedLookupAppender(16));
203:                harness.addProduct(new CombinedLookupReplacer(0));
204:                harness.addProduct(new CombinedLookupReplacer(16));
205:                harness.addProduct(new IterativeAppender(0));
206:                harness.addProduct(new IterativeAppender(16));
207:                harness.addProduct(new IterativeReplacer(0));
208:                harness.addProduct(new IterativeReplacer(16));
209:                harness.addProduct(new SeparateLookupReplacer(0));
210:                harness.addProduct(new SeparateLookupReplacer(16));
211:                harness.addTarget(new FieldReflection());
212:                harness.addTarget(new Field_Reflection());
213:                harness.addTarget(new Field$Reflection());
214:                harness.run(new MultiReporter(reporters) {
215:
216:                    public void startBenchmark() {
217:                        // do nothing
218:                    }
219:
220:                });
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.