db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r431356 - /db/ojb/trunk/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java
Date Mon, 14 Aug 2006 14:42:23 GMT
Author: arminw
Date: Mon Aug 14 07:42:22 2006
New Revision: 431356

URL: http://svn.apache.org/viewvc?rev=431356&view=rev
Log:
improve test

Modified:
    db/ojb/trunk/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java?rev=431356&r1=431355&r2=431356&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/IdentityPerformanceTest.java Mon Aug 14 07:42:22
2006
@@ -9,63 +9,102 @@
 /**
  * @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 PBTestCase
 {
-    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 = ojb.getMetadataManager().getRepository();
-        for (int i = 0; i < ITERATIONS; i++)
+        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


Mime
View raw message