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


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.cache.implementation;
011:
012:        import org.mmbase.cache.CacheImplementationInterface;
013:        import java.util.*;
014:
015:        /**
016:         Some results (at 2 x (dual core)  Intel(R) Core(TM)2 CPU         T7200  @ 2.00GHz)
017:         <pre>
018:         michiel@mitulo:~/mmbase/head$ java org.mmbase.cache.implementation.Test 1025 1000000 50 org.mmbase.cache.implementation.LRUCache
019:         Size 512
020:         [+0][+1][+2][+3][+8][+6][+7][+5][+4][+9][+10][+11][+12][+13][+14][+15][+16][+17][+18][+19][+20][+21][+22][+23][+26][+27][+28][+24][+29][+30][+31][+32][+33][+34][+35][+36][+37][+38][+39][+40][+41][+42][+43][+44][+45][+46][+47][+48][+25][+49][-45][-20][-43][-41][-47][-46][-16][-4][-12][-6][-2][-15][-8][-21][-18][-22][-17][-28][-27][-26][-29][-30][-24][-13][-39][-34][-40][-42][-44][-25][-37][-1][-3][-11][-0][-49][-7][-14][-19][-48][-33][-31][-36][-5][-35][-38][-9][-23][-32][-10].
021:         Creation 8 ns
022:         Thread starting 147728 us
023:         Not printed (too huge)
024:         Run      62635 ms (62635 us/koperation,  1252 us/koperation total from 50 threads)
025:         Used implementation: class org.mmbase.cache.implementation.LRUCache
026:         michiel@mitulo:~/mmbase/head$ java org.mmbase.cache.implementation.Test 1025 1000000 50 org.mmbase.util.LRUHashtable
027:         Size 512
028:         [+0][+1][+2][+3][+4][+5][+6][+7][+8][+9][+10][+12][+13][+11][+14][+15][+16][+17][+18][+20][+19][+21][+22][+23][+24][+25][+26][+27][+28][+30][+31][+32][+33][+34][+35][+36][+37][+38][+39][+40][+41][+42][+43][+44][+45][+46][+47][+48][+49][+29][-20][-47][-42][-39][-36][-38][-27][-21][-23][-22][-16][-10][-17][-12][-8][-3][-4][-49][-48][-2][-44][-35][-43][-30][-32][-11][-34][-25][-31][-19][-33][-1][-24][-37][-0][-40][-41][-13][-9][-45][-18][-15][-7][-28][-29][-26][-46][-5][-6][-14].
029:         Creation 8 ns
030:         Thread starting 130541 us
031:         Not printed (too huge)
032:         Run      67879 ms (67879 us/koperation,  1357 us/koperation total from 50 threads)
033:         Used implementation: class org.mmbase.util.LRUHashtable
034:         michiel@mitulo:~/mmbase/head$ 
035:         </pre>
036:
037:         * Conclusion: No difference. I think we can just as well use LRUCache, since it is less code.
038:         *
039:         * @author  Rico Jansen (in org.mmbase.util.LRUHashtable)
040:         * @author  Michiel Meeuwissen
041:         * @version $Id: Test.java,v 1.2 2008/02/03 17:33:57 nklasens Exp $
042:         * @see    org.mmbase.cache.Cache
043:         * @since MMBase-1.9
044:         */
045:        public class Test {
046:
047:            public static void main(String argv[]) throws Exception {
048:                Class<?> impl = LRUCache.class;
049:                int treesiz = 1024;
050:                int opers = 1000000;
051:                int thrds = 1;
052:
053:                try {
054:                    if (argv.length > 0) {
055:                        treesiz = Integer.parseInt(argv[0]);
056:                    }
057:                    if (argv.length > 1) {
058:                        opers = Integer.parseInt(argv[1]);
059:                    }
060:                    if (argv.length > 2) {
061:                        thrds = Integer.parseInt(argv[2]);
062:                    }
063:
064:                    if (argv.length > 3) {
065:                        impl = Class.forName(argv[3]);
066:                    }
067:                } catch (Exception e) {
068:                    System.out
069:                            .println("Usage: java org.mmbase.util.LRUHashtable <size of table> <number of operation to do> <threads> <class name>");
070:                    return;
071:                }
072:
073:                final CacheImplementationInterface<String, String> treap = (CacheImplementationInterface<String, String>) impl
074:                        .newInstance();
075:                treap.setMaxSize(treesiz / 2);
076:                long ll1 = System.currentTimeMillis();
077:
078:                // fill the map
079:                for (int i = 0; i < treesiz; i++) {
080:                    treap.put("" + i, "" + i);
081:                }
082:                long ll2 = System.currentTimeMillis();
083:                System.out.println("Size " + treap.size());
084:
085:                if (treesiz <= 1024) {
086:                    System.out.println("LRUHashtable initially "
087:                            + treap.entrySet());
088:                }
089:                final int TREESIZ = treesiz;
090:                final int OPERS = opers;
091:
092:                final int score[][] = new int[TREESIZ][thrds];
093:                long ll3 = System.nanoTime();
094:
095:                final Thread[] threads = new Thread[thrds];
096:                for (int t = 0; t < thrds; t++) {
097:                    final int threadnr = t;
098:                    Runnable runnable = new Runnable() {
099:                        public void run() {
100:                            if (threads.length > 1) {
101:                                System.out.print("[+" + threadnr + "]");
102:                            }
103:                            Random rnd = new Random();
104:                            for (int i = 0; i < OPERS; i++) {
105:                                // Put and get mixed
106:                                int j = Math.abs(rnd.nextInt()) % (TREESIZ / 2)
107:                                        + (TREESIZ / 4);
108:                                int k = Math.abs(rnd.nextInt()) % 2;
109:                                switch (k) {
110:                                case 0:
111:                                    treap.put("" + j, "" + j);
112:                                    score[j][threadnr]++;
113:                                    break;
114:                                case 1:
115:                                    treap.get("" + j);
116:                                    score[j][threadnr]++;
117:                                    break;
118:                                }
119:                                // Only a get
120:                                j = Math.abs(rnd.nextInt()) % (TREESIZ);
121:                                treap.get("" + j);
122:                                score[j][threadnr]++;
123:                            }
124:                            if (threads.length > 1) {
125:                                System.out.print("[-" + threadnr + "]");
126:                            }
127:                        }
128:                    };
129:                    threads[t] = new Thread(runnable);
130:                    threads[t].start();
131:                }
132:                long ll4 = System.nanoTime();
133:                for (int i = 0; i < thrds; i++) {
134:                    try {
135:                        threads[i].join();
136:                    } catch (InterruptedException ie) {
137:                        System.err.println("Interrupted");
138:                    }
139:                }
140:                System.out.println(".");
141:                long ll5 = System.nanoTime();
142:                if (TREESIZ <= 1024) {
143:                    System.out.println("LRUHashtable afterwards "
144:                            + treap.entrySet());
145:
146:                    for (int i = 0; i < TREESIZ; i++) {
147:                        int totscore = 0;
148:                        for (int j = 0; j < thrds; j++) {
149:                            totscore += score[i][j];
150:                        }
151:                        System.out.println("" + i + " score " + totscore);
152:                    }
153:                }
154:                System.out.println("Creation " + (ll2 - ll1) + " ns");
155:                System.out.println("Thread starting " + (ll4 - ll3) / 1000
156:                        + " us");
157:                if (TREESIZ <= 1024) {
158:                    System.out.println("Print    " + (ll3 - ll2) / 1000000
159:                            + " ms");
160:                } else {
161:                    System.out.println("Not printed (too huge)");
162:                }
163:                long timePerKop = (ll5 - ll3) * 1000 / (opers);
164:                System.out.println("Run      " + (ll5 - ll3) / 1000000
165:                        + " ms (" + timePerKop / 1000 + " us/koperation,  "
166:                        + (timePerKop / thrds) / 1000
167:                        + " us/koperation total from " + thrds + " threads)");
168:                System.out.println("Used implementation: " + impl);
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.