Source Code Cross Referenced for BenchmarkRunner.java in  » Cache » whirlycache » com » whirlycott » cache » benchmarks » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » whirlycache » com.whirlycott.cache.benchmarks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Oct 10, 2004 by pjacob
003:         *
004:         */
005:        package com.whirlycott.cache.benchmarks;
006:
007:        import java.io.File;
008:        import java.io.IOException;
009:        import java.util.ArrayList;
010:        import java.util.Date;
011:        import java.util.HashMap;
012:        import java.util.Iterator;
013:        import java.util.List;
014:        import java.util.Map;
015:
016:        import org.apache.commons.logging.Log;
017:        import org.apache.commons.logging.LogFactory;
018:        import org.jfree.chart.ChartUtilities;
019:        import org.jfree.chart.JFreeChart;
020:        import org.jfree.chart.axis.CategoryAxis;
021:        import org.jfree.chart.axis.CategoryAxis3D;
022:        import org.jfree.chart.axis.NumberAxis3D;
023:        import org.jfree.chart.axis.ValueAxis;
024:        import org.jfree.chart.plot.CategoryPlot;
025:        import org.jfree.chart.renderer.category.BarRenderer3D;
026:        import org.jfree.data.category.DefaultCategoryDataset;
027:
028:        /**
029:         * @author pjacob
030:         *
031:         */
032:        public class BenchmarkRunner {
033:
034:            /**
035:             * Number of concurrent threads.
036:             */
037:            public final static int CONCURRENT_THREADS = 20;
038:
039:            /**
040:             * Number of elements in the cache
041:             */
042:            private static final int ELEMENTS_CACHED = 50000;
043:
044:            /**
045:             * Number of iterations that the benchmark will be run.
046:             */
047:            public final static int ITERATIONS_PER_BENCHMARK = 10;
048:
049:            /**
050:             * Logger.
051:             */
052:            private static final Log log = LogFactory
053:                    .getLog(BenchmarkRunner.class);
054:
055:            /**
056:             * Percent of read-only activity: 8 = 80%, 5 = 50%, etc.
057:             */
058:            public final static int PERCENT_READONLY = 8;
059:
060:            /**
061:             * How many milliseconds should we do a Thread.sleep(n) between tests.
062:             */
063:            public final static int SLEEPTIME_BETWEEN_TESTS = 11000;
064:
065:            /**
066:             * Entry point into the benchmarking code.
067:             * @param args
068:             * @throws IOException
069:             */
070:            public static void main(final String[] args) throws Exception {
071:
072:                //Just add in new cache bencharkables here and the rest is automatic.
073:                final Map benchmarkableCaches = new HashMap();
074:
075:                //Test params
076:                final Params testParams = new Params(ELEMENTS_CACHED,
077:                        CONCURRENT_THREADS);
078:
079:                benchmarkableCaches.put(new StandardHashmap(), testParams);
080:
081:                benchmarkableCaches.put(new Ehcache(), testParams);
082:
083:                benchmarkableCaches.put(new Whirlycache(), testParams);
084:
085:                benchmarkableCaches.put(new Oscache(), testParams);
086:
087:                benchmarkableCaches.put(new ApacheJCS(), testParams);
088:
089:                benchmarkableCaches.put(new JBossCache(), testParams);
090:
091:                //Store the results in a list.
092:                final List results = new ArrayList();
093:
094:                /*
095:                 * Run each benchmark.
096:                 */
097:                for (final Iterator i = benchmarkableCaches.keySet().iterator(); i
098:                        .hasNext();) {
099:                    final Benchmarkable b = (Benchmarkable) i.next();
100:                    log.debug("Starting test: " + b.getName());
101:
102:                    final Params p = (Params) benchmarkableCaches.get(b);
103:                    final Result result = b.benchmark(p);
104:                    results.add(result);
105:                    log.debug("Benchmark for " + b.getName()
106:                            + " with settings " + p.getShortName() + ": "
107:                            + result.getTime());
108:
109:                    //Do a gc between each test.
110:                    System.gc();
111:
112:                    log.debug("Sleeping between tests...");
113:                    Thread.sleep(SLEEPTIME_BETWEEN_TESTS);
114:
115:                }
116:
117:                //Print out a graphic.
118:                makeGraph(results);
119:
120:            }
121:
122:            /**
123:             * Make the graphic.
124:             * @param _results
125:             * @throws IOException
126:             */
127:            public static void makeGraph(final List _results)
128:                    throws IOException {
129:                final CategoryPlot plot = new CategoryPlot();
130:
131:                //Create jfree objects based on the List of results passed in
132:                int counter = 0;
133:                final DefaultCategoryDataset d = new DefaultCategoryDataset();
134:                for (final Iterator i = _results.iterator(); i.hasNext();) {
135:
136:                    final Result result = (Result) i.next();
137:                    d.addValue(result.getTime(), result.getName(), result
138:                            .getName());
139:                    log.debug("Adding: " + result.getName() + " with time "
140:                            + result.getTime());
141:                    plot.setDataset(counter, d);
142:                    counter++;
143:                }
144:
145:                plot.setRenderer(new BarRenderer3D());
146:
147:                final CategoryAxis domainAxis = new CategoryAxis3D();
148:                plot.setDomainAxis(domainAxis);
149:
150:                final ValueAxis rangeAxis = new NumberAxis3D();
151:                rangeAxis.setLabel("Milliseconds");
152:                plot.setRangeAxis(rangeAxis);
153:                plot.setForegroundAlpha(0.7f);
154:
155:                final JFreeChart chart = new JFreeChart(
156:                        "Whirlycache Benchmarks at " + new Date(), plot);
157:                chart.setAntiAlias(true);
158:
159:                final String file = System.getProperty("java.io.tmpdir")
160:                        + "whirlycache-results.png";
161:                log.debug("Writing results to " + file);
162:                final File f = new File(file);
163:
164:                ChartUtilities.saveChartAsPNG(f, chart, 500, 500);
165:            }
166:
167:            public BenchmarkRunner() {
168:                super();
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.