You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2006/08/14 16:41:22 UTC
svn commit: r431355 -
/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java
Author: arminw
Date: Mon Aug 14 07:41:21 2006
New Revision: 431355
URL: http://svn.apache.org/viewvc?rev=431355&view=rev
Log:
improve test
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java?rev=431355&r1=431354&r2=431355&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java Mon Aug 14 07:41:21 2006
@@ -1,74 +1,110 @@
package org.apache.ojb.broker;
-import junit.framework.TestCase;
-
import java.util.Map;
import java.util.HashMap;
import org.apache.ojb.broker.metadata.DescriptorRepository;
-import org.apache.ojb.broker.metadata.MetadataManager;
+import org.apache.ojb.junit.PBTestCase;
/**
* @author Matthew.Baird
*
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
*/
-public class IdentityPerformanceTest extends TestCase
+public class IdentityPerformanceTest extends PBTestCase
{
- PersistenceBroker broker;
- private static Class CLASS = IdentityPerformanceTest.class;
- private static final int ITERATIONS = 10000;
+ private static final int ITERATIONS = 300000;
public static void main(String[] args)
{
- String[] arr = {CLASS.getName()};
+ String[] arr = {IdentityPerformanceTest.class.getName()};
junit.textui.TestRunner.main(arr);
}
- public void testIdentityIterations()
+ public void testIdentityHandlingPerformance() throws Exception
+ {
+ doDescriptorRepositoryGetDescriptorForIterations();
+ System.gc();
+ System.gc();
+ //Thread.sleep(1000);
+ long oidCreation = doIdentityIterations();
+ System.gc();
+ System.gc();
+ //Thread.sleep(1000);
+ long mapCreation = doMapIterations();
+ System.gc();
+ System.gc();
+
+ /*
+ This is a critical test, because we do a performance comparison
+ of class instantion time which strongly depends on used hardware
+ and JDK version.
+ */
+// String msg = "\n This is a critical test, because we do a performance comparison\n" +
+// " of class instantiation time which strongly depends on used hardware\n" +
+// " and JDK version.\n" +
+// " But it seems that creation of Identity objects is a bit slow.\n" +
+// " Please check source code handling Identity object creation.";
+// boolean ratio = (oidCreation / mapCreation) > 10;
+// System.out.println("Ratio IdentityCreation/MapCreation <==> " + oidCreation / mapCreation + ":1");
+// assertFalse(msg, ratio);
+ }
+
+ public long doIdentityIterations()
{
Article art = new Article();
art.setArticleName("OJB O/R mapping power");
ProductGroup pg = new ProductGroup();
pg.setName("Software");
art.setProductGroup(pg);
+ broker.beginTransaction();
+ broker.store(art);
+ broker.commitTransaction();
+
// prime the pump.
- Identity artOID = new Identity(art,broker);
+ broker.serviceIdentity().buildIdentity(art);
long start = System.currentTimeMillis();
- for (int i = 0; i < ITERATIONS; i++)
+ Identity artOID;
+ for(int i = 0; i < ITERATIONS; i++)
{
- artOID = new Identity(art,broker);
+ artOID = broker.serviceIdentity().buildIdentity(art);
+ assertNotNull(artOID);
}
long stop = System.currentTimeMillis();
System.out.println("total time to build " + ITERATIONS + " identities " + (stop - start) + " ms.");
- System.out.println("time to build one Identity " + ((stop - start) / ITERATIONS) + " ms.");
+ //System.out.println("time to build one Identity " + ((stop - start) / ITERATIONS) + " ms.");
+ return stop - start;
}
- public void testMapIterations()
+
+ public long doMapIterations()
{
long start = System.currentTimeMillis();
Map temp;
-
- for (int i = 0; i < ITERATIONS; i++)
+ for(int i = 0; i < ITERATIONS; i++)
{
temp = new HashMap();
+ assertNotNull(temp);
}
long stop = System.currentTimeMillis();
System.out.println("total time to build " + ITERATIONS + " HashMaps " + (stop - start) + " ms.");
- System.out.println("time to build one HashMaps " + ((stop - start) / ITERATIONS) + " ms.");
+ //System.out.println("time to build one HashMaps " + ((stop - start) / ITERATIONS) + " ms.");
+ return stop - start;
}
- public void testDescriptorRepositoryGetDescriptorForIterations()
+
+ public long doDescriptorRepositoryGetDescriptorForIterations()
{
long start = System.currentTimeMillis();
- DescriptorRepository descriptorRepository = MetadataManager.getInstance().getRepository();
- for (int i = 0; i < ITERATIONS; i++)
+ DescriptorRepository descriptorRepository = broker.getDescriptorRepository();
+ for(int i = 0; i < ITERATIONS; i++)
{
descriptorRepository.getDescriptorFor(Article.class);
}
long stop = System.currentTimeMillis();
System.out.println("total time to getDescriptorFor " + ITERATIONS + " times " + (stop - start) + " ms.");
- System.out.println("time to call one getDescriptorFor " + ((stop - start) / ITERATIONS) + " ms.");
+ //System.out.println("time to call one getDescriptorFor " + ((stop - start) / ITERATIONS) + " ms.");
+ return stop - start;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org