01: /*
02: Copyright 2004 Philip Jacob <phil@whirlycott.com>
03: Seth Fitzsimmons <seth@note.amherst.edu>
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: */
17:
18: /*
19: * Created on May 16, 2004
20: *
21: */
22: package com.whirlycott.cache.test;
23:
24: import net.sf.ehcache.Cache;
25: import net.sf.ehcache.CacheException;
26: import net.sf.ehcache.CacheManager;
27: import net.sf.ehcache.Element;
28:
29: import org.apache.commons.logging.Log;
30: import org.apache.commons.logging.LogFactory;
31:
32: /**
33: * @author phil
34: */
35: public class BenchmarkEhcache {
36:
37: private static Log log = LogFactory.getLog(BenchmarkEhcache.class);
38:
39: public static void main(String[] args) throws CacheException {
40:
41: log.debug("Setting up the cache...");
42: CacheManager cacheManager = CacheManager.create();
43:
44: Cache cache = new Cache("test", Constants.STORE_COUNT, false,
45: false, 3600, 3600);
46: cacheManager.addCache(cache);
47:
48: //BEGIN PUT TEST
49: long start = System.currentTimeMillis();
50: //Do puts.
51: for (int i = 0; i < Constants.STORE_COUNT; i++) {
52: Element e = new Element(new Integer(i).toString(), "value"
53: + i);
54: cache.put(e);
55: }
56: long end = System.currentTimeMillis();
57: log.debug("Total PUT time was: " + (end - start));
58: //END PUT TEST
59:
60: //---------------------------------------------
61:
62: //BEGIN GET TEST
63: long startGet = System.currentTimeMillis();
64:
65: for (int i = 0; i < Constants.RETRIEVE_COUNT; i++) {
66: for (int loop = 0; loop < Constants.STORE_COUNT; loop++) {
67: Element e = cache.get(new Integer(loop).toString());
68: Object o = e.getValue();
69: }
70: }
71:
72: long endGet = System.currentTimeMillis();
73: log.debug("Total GET time: " + (endGet - startGet));
74: //END GET TEST
75:
76: //BEGIN MULTITHREAD GET
77: long startMGet = System.currentTimeMillis();
78:
79: long endMGet = System.currentTimeMillis();
80: //END MULTITHREAD GET
81:
82: //BEGIN MULTITHREAD GET/PUT
83: long startMG = System.currentTimeMillis();
84:
85: long endMG = System.currentTimeMillis();
86: //END MULTITHREAD GET/PUT
87:
88: log.debug("Shutting down the cache...");
89: cacheManager.shutdown();
90: log.debug("Done.");
91:
92: }
93: }
|