db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r472132 - /db/ojb/trunk/src/test/org/apache/ojb/performance/PerfMain.java
Date Tue, 07 Nov 2006 15:13:45 GMT
Author: arminw
Date: Tue Nov  7 07:13:44 2006
New Revision: 472132

URL: http://svn.apache.org/viewvc?view=rev&rev=472132
Log:
minor improvements

Modified:
    db/ojb/trunk/src/test/org/apache/ojb/performance/PerfMain.java

Modified: db/ojb/trunk/src/test/org/apache/ojb/performance/PerfMain.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/performance/PerfMain.java?view=diff&rev=472132&r1=472131&r2=472132
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/performance/PerfMain.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/performance/PerfMain.java Tue Nov  7 07:13:44 2006
@@ -19,7 +19,6 @@
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.PrintStream;
-import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -337,7 +336,7 @@
             if(k==TEST_INSERT)
             {
                 double[] resultArray = calibration[TEST_INSERT];
-                double minimum = NumberUtils.min(resultArray);
+                double minimum = smartMinimum("insert", resultArray);
                 for(int i = 0; i < results.length; i++)
                 {
                     results[i].setInsertMinimun(minimum);
@@ -346,7 +345,7 @@
             if(k==TEST_FETCH)
             {
                 double[] resultArray = calibration[TEST_FETCH];
-                double minimum = NumberUtils.min(resultArray);
+                double minimum = smartMinimum("fetch", resultArray);
                 for(int i = 0; i < results.length; i++)
                 {
                     results[i].setFetchMinimun(minimum);
@@ -355,7 +354,7 @@
             if(k==TEST_FETCH_2)
             {
                 double[] resultArray = calibration[TEST_FETCH_2];
-                double minimum = NumberUtils.min(resultArray);
+                double minimum = smartMinimum("fetch_2", resultArray);
                 for(int i = 0; i < results.length; i++)
                 {
                     results[i].setFetchSecondMinimun(minimum);
@@ -364,7 +363,7 @@
             if(k==TEST_BY_IDENTITY)
             {
                 double[] resultArray = calibration[TEST_BY_IDENTITY];
-                double minimum = NumberUtils.min(resultArray);
+                double minimum = smartMinimum("by identity", resultArray);
                 for(int i = 0; i < results.length; i++)
                 {
                     results[i].setByIdentityMinimun(minimum);
@@ -373,7 +372,7 @@
             if(k==TEST_UPDATE)
             {
                 double[] resultArray = calibration[TEST_UPDATE];
-                double minimum = NumberUtils.min(resultArray);
+                double minimum = smartMinimum("update", resultArray);
                 for(int i = 0; i < results.length; i++)
                 {
                     results[i].setUpdateMinimun(minimum);
@@ -382,7 +381,7 @@
             if(k==TEST_DELETE)
             {
                 double[] resultArray = calibration[TEST_DELETE];
-                double minimum = NumberUtils.min(resultArray);
+                double minimum = smartMinimum("delete", resultArray);
                 for(int i = 0; i < results.length; i++)
                 {
                     results[i].setDeleteMinimun(minimum);
@@ -554,7 +553,7 @@
         return alignToLength("", length, fillCharacter, false);
     }
 
-    private String alignToLength(String target, int length, String fillCharacter, boolean
right)
+    private static String alignToLength(String target, int length, String fillCharacter,
boolean right)
     {
         if (target.length() > length) return target;
 
@@ -576,7 +575,7 @@
      * testTimes[5] updating times
      * testTimes[6] deleting times
      */
-    public synchronized void addPeriodResult(String testName, double[] resultArr, boolean
isValid)
+    synchronized void addPeriodResult(String testName, double[] resultArr, boolean isValid)
     {
         PerfResult result = (PerfResult) resultMap.get(testName);
         if (result == null)
@@ -618,7 +617,7 @@
         }
     }
 
-    public synchronized void addConsistentResult(String testName, int objectsBefore, int
objectsAfter)
+    synchronized void addConsistentResult(String testName, int objectsBefore, int objectsAfter)
     {
         ConsistentEntry ce = new ConsistentEntry(objectsBefore, objectsAfter);
         PerfResult result = (PerfResult) resultMap.get(testName);
@@ -636,7 +635,7 @@
         result.addConsistentEntry(ce);
     }
 
-    public synchronized void registerException(String causer, Exception e)
+    synchronized void registerException(String causer, Exception e)
     {
         exceptionMap.put(causer, e);
     }
@@ -672,22 +671,22 @@
     }
 
 
-    Object newInstance(Class target, Class argType, Object argInstance)
-    {
-        try
-        {
-            Class[] types = new Class[]{argType};
-            Object[] args = new Object[]{argInstance};
-            Constructor con = target.getConstructor(types);
-            return con.newInstance(args);
-        }
-        catch(Exception e)
-        {
-            e.printStackTrace();
-            throw new RuntimeException("Can't create instance for class "
-                    + target + "using constructor argument " + argType + ", message is "
+ e.getMessage());
-        }
-    }
+//    static Object newInstance(Class target, Class argType, Object argInstance)
+//    {
+//        try
+//        {
+//            Class[] types = new Class[]{argType};
+//            Object[] args = new Object[]{argInstance};
+//            Constructor con = target.getConstructor(types);
+//            return con.newInstance(args);
+//        }
+//        catch(Exception e)
+//        {
+//            e.printStackTrace();
+//            throw new RuntimeException("Can't create instance for class "
+//                    + target + "using constructor argument " + argType + ", message is
" + e.getMessage());
+//        }
+//    }
 
     static String smartRounding(double value)
     {
@@ -716,12 +715,29 @@
             if(printer != null)
             {
                 printer.println();
-                printer.println("## Unexact percent result generated, give value was <=0
--> use approximated value 0.5 to fix ##");
+                printer.println("## Undefined value (<=0), can't calculate percent -->
use approximated value 0.1 to fix ##");
                 printer.println();
             }
-            value = 0.5d;
+            value = 0.1d;
         }
         return Math.round((value / calibration) * 100);
+    }
+
+    static double smartMinimum(String name, double[] resultArray)
+    {
+        double result = NumberUtils.min(resultArray);
+        if(result <= 0d)
+        {
+            if(printer != null)
+            {
+                name = name != null ? "'" + name + "'" : "test";
+                printer.println();
+                printer.println("## Can't calculate minimum " + name + " period, minimum
value is <=0 --> use approximated value 0.1 as minimum ##");
+                printer.println();
+            }
+            result = 0.1d;
+        }
+        return result;
     }
 
 



---------------------------------------------------------------------
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