svn commit: r472131 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java

[email protected]
Newsgroups gmane.comp.jakarta.ojb.devel
Message-ID <[email protected]>
Author: arminw
Date: Tue Nov  7 07:13:13 2006
New Revision: 472131

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

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

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java?view=diff&rev=472131&r1=472130&r2=472131
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java Tue Nov  7 07:13:13 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;
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.