[jboss-cvs] JBossCache/tests-50/perf/org/jboss/cache/pojo/collection ...
Elias Ross
genman at noderunner.net
Fri Nov 10 00:19:04 EST 2006
User: genman
Date: 06/11/10 00:19:04
Added: tests-50/perf/org/jboss/cache/pojo/collection
CollectionPerfTest.java
Log:
Migrate perf tests to perf directory
Revision Changes Path
1.1 date: 2006/11/10 05:19:04; author: genman; state: Exp;JBossCache/tests-50/perf/org/jboss/cache/pojo/collection/CollectionPerfTest.java
Index: CollectionPerfTest.java
===================================================================
package org.jboss.cache.pojo.collection;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import junit.framework.TestCase;
/**
* Tests POJO Collection classes' performance.
*/
public class CollectionPerfTest extends TestCase
{
Log log_ = LogFactory.getLog(CollectionTest.class);
PojoCache cache_;
protected void setUp() throws Exception
{
super.setUp();
log_.info("test " + getName());
String configFile = "META-INF/local-service.xml";
boolean toStart = false;
cache_ = PojoCacheFactory.createCache(configFile, toStart);
cache_.start();
}
protected void tearDown() throws Exception
{
super.tearDown();
cache_.stop();
}
/**
* Commented it out now. We should move this to perf directory.
*
* @throws Exception
*/
public void testListAddPerformance() throws Exception
{
Collection cache_List = new LinkedList();
Collection jdkList = new LinkedList();
addPerformance(cache_List, jdkList, "List");
}
public void testSetAddPerformance() throws Exception
{
Collection cache_List = new HashSet();
Collection jdkList = new HashSet();
addPerformance(cache_List, jdkList, "Set");
}
public void testMapAddPerformance() throws Exception
{
Map cacheList = new HashMap();
Map jdkList = new HashMap();
addPerformance(cacheList, jdkList, "Map");
}
public void testListIterPerformance() throws Exception
{
Collection cacheList = new LinkedList();
Collection jdkList = new LinkedList();
iterPerformance(cacheList, jdkList, "List");
}
public void testSetIterPerformance() throws Exception
{
Collection cacheList = new HashSet();
Collection jdkList = new HashSet();
iterPerformance(cacheList, jdkList, "Set");
}
public void testMapIterPerformance() throws Exception
{
Map cacheList = new HashMap();
Map jdkList = new HashMap();
iterPerformance(cacheList, jdkList, "Map");
}
public void addPerformance(Collection cacheList, Collection jdkList, String label) throws Exception
{
try
{
cache_.attach("/language/list", cacheList);
cacheList = (Collection) cache_.find("/language/list");
long start = System.currentTimeMillis();
collectionAdd(1000, jdkList);
long jdkTime = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
collectionAdd(1000, cacheList);
long cacheTime = System.currentTimeMillis() - start;
//assertTrue(label + " 1000 add performance, jdk time=" + jdkTime +", cache time=" + cacheTime, goodEnough(cacheTime,jdkTime));
log_.info(label + " 1000 add performance, jdk time=" + jdkTime + ", cache time=" + cacheTime);
}
catch (Exception e)
{
fail("testAddAll " + e.getMessage());
throw e;
}
}
public void addPerformance(Map cacheList, Map jdkList, String label) throws Exception
{
try
{
cache_.attach("/language/list", cacheList);
cacheList = (Map) cache_.find("/language/list");
long start = System.currentTimeMillis();
collectionAdd(1000, jdkList);
long jdkTime = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
collectionAdd(1000, cacheList);
long cacheTime = System.currentTimeMillis() - start;
//assertTrue(label + " 1000 add performance, jdk time=" + jdkTime +", cache time=" + cacheTime, goodEnough(cacheTime,jdkTime));
log_.info(label + " 1000 add performance, jdk time=" + jdkTime + ", cache time=" + cacheTime);
}
catch (Exception e)
{
fail("testAddAll " + e.getMessage());
throw e;
}
}
public void iterPerformance(Collection cacheList, Collection jdkList, String label) throws Exception
{
cache_.attach("/language/list", cacheList);
cacheList = (Collection) cache_.find("/language/list");
collectionAdd(1000, jdkList);
collectionAdd(1000, cacheList);
long start = System.currentTimeMillis();
Iterator iter = jdkList.iterator();
while (iter.hasNext())
iter.next();
long jdkTime = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
iter = cacheList.iterator();
while (iter.hasNext())
iter.next();
long cacheTime = System.currentTimeMillis() - start;
//assertTrue(label + " 1000 iter performance, jdk time=" + jdkTime +", cache time=" + cacheTime, goodEnough(cacheTime,jdkTime));
log_.info(label + " 1000 iter performance, jdk time=" + jdkTime + ", cache time=" + cacheTime);
}
public void iterPerformance(Map cacheList, Map jdkList, String label) throws Exception
{
cache_.attach("/language/list", cacheList);
cacheList = (Map) cache_.find("/language/list");
collectionAdd(1000, jdkList);
collectionAdd(1000, cacheList);
long start = System.currentTimeMillis();
Iterator iter = jdkList.keySet().iterator();
while (iter.hasNext())
iter.next();
long jdkTime = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
iter = cacheList.keySet().iterator();
while (iter.hasNext())
iter.next();
long cacheTime = System.currentTimeMillis() - start;
//assertTrue(label + " 1000 iter performance, jdk time=" + jdkTime +", cache time=" + cacheTime, goodEnough(cacheTime,jdkTime));
log_.info(label + " 1000 iter performance, jdk time=" + jdkTime + ", cache time=" + cacheTime);
}
public void collectionAdd(int count, Collection c) throws Exception
{
for (int looper = 0; looper < count; looper++)
{
String value = Integer.toString(looper);
c.add(value);
}
}
public void collectionAdd(int count, Map c) throws Exception
{
for (int looper = 0; looper < count; looper++)
{
String value = Integer.toString(looper);
c.put(value, value);
}
}
public boolean goodEnough(double cacheTime, double jdkTime)
{
if (jdkTime == 0)
jdkTime = 1;
double percent = ((cacheTime - jdkTime) / jdkTime) * 100.0;
log_.info("percent =" + percent + " cache=" + cacheTime + " jdk =" + jdkTime);
return percent < 100.0;
}
}
More information about the jboss-cvs-commits
mailing list