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


001:        /*
002:         * Copyright (C) 2006 Joe Walnes.
003:         * Copyright (C) 2006, 2007, 2008 XStream Committers.
004:         * All rights reserved.
005:         *
006:         * The software in this package is published under the terms of the BSD
007:         * style license a copy of which has been included with this distribution in
008:         * the LICENSE.txt file.
009:         * 
010:         * Created on 15. July 2006 by Joe Walnes
011:         */
012:        package com.thoughtworks.xstream.tools.benchmark.metrics;
013:
014:        import com.thoughtworks.xstream.tools.benchmark.Metric;
015:        import com.thoughtworks.xstream.tools.benchmark.Product;
016:        import com.thoughtworks.xstream.tools.benchmark.Target;
017:
018:        import java.io.ByteArrayOutputStream;
019:        import java.io.ByteArrayInputStream;
020:
021:        /**
022:         * Determines how long it takes to deserialize an object (in ms).
023:         *
024:         * @author Joe Walnes
025:         * @author Jörg Schaible
026:         * @see com.thoughtworks.xstream.tools.benchmark.Harness
027:         * @see Metric
028:         */
029:        public class DeserializationSpeedMetric implements  Metric {
030:
031:            private final int iterations;
032:            private final boolean validate;
033:
034:            /**
035:             * Measure deserialization speed.
036:             * 
037:             * @param iterations
038:             * @deprecated since 1.3, use {@link #DeserializationSpeedMetric(int, boolean)}
039:             */
040:            public DeserializationSpeedMetric(int iterations) {
041:                this (iterations, false);
042:            }
043:
044:            /**
045:             * Measure deserialization speed.
046:             * @param iterations 
047:             * @param validate flag to compare result of last iteration with original data
048:             * @since 1.3
049:             */
050:            public DeserializationSpeedMetric(int iterations, boolean validate) {
051:                this .iterations = iterations;
052:                this .validate = validate;
053:            }
054:
055:            public double run(Product product, Target target) throws Exception {
056:
057:                // Serialize once (because we need something to deserialize).
058:                ByteArrayOutputStream output = new ByteArrayOutputStream();
059:                product.serialize(target.target(), output);
060:                byte[] data = output.toByteArray();
061:
062:                // Deserialize once, to warm up.
063:                product.deserialize(new ByteArrayInputStream(data));
064:
065:                // Now lots of times
066:                Object lastResult = null;
067:                long start = System.currentTimeMillis();
068:                for (int i = 0; i < iterations; i++) {
069:                    lastResult = product.deserialize(new ByteArrayInputStream(
070:                            data));
071:                }
072:                long end = System.currentTimeMillis();
073:                if (validate && iterations > 0) {
074:                    if (!target.isEqual(lastResult)) {
075:                        throw new RuntimeException(
076:                                "Deserialized object is not equal");
077:                    }
078:                }
079:
080:                return (end - start);
081:            }
082:
083:            /**
084:             *@deprecated since 1.3
085:             */
086:            public double run(Product product, Object object) throws Exception {
087:
088:                // Serialize once (because we need something to deserialize).
089:                ByteArrayOutputStream output = new ByteArrayOutputStream();
090:                product.serialize(object, output);
091:                byte[] data = output.toByteArray();
092:
093:                // Deserialize once, to warm up.
094:                product.deserialize(new ByteArrayInputStream(data));
095:
096:                // Now lots of times
097:                long start = System.currentTimeMillis();
098:                for (int i = 0; i < iterations; i++) {
099:                    product.deserialize(new ByteArrayInputStream(data));
100:                }
101:                long end = System.currentTimeMillis();
102:
103:                return (end - start);
104:            }
105:
106:            public String unit() {
107:                return "ms";
108:            }
109:
110:            public boolean biggerIsBetter() {
111:                return false;
112:            }
113:
114:            public String toString() {
115:                return "Deserialization speed (" + iterations + " iteration"
116:                        + (iterations == 1 ? "" : "s") + ")";
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.