commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bur...@apache.org
Subject svn commit: r157305 - in jakarta/commons/sandbox/benchmark/trunk/src: java/org/apache/commons/benchmark/BenchmarkMeta.java java/org/apache/commons/benchmark/BenchmarkMethodMeta.java java/org/apache/commons/benchmark/BenchmarkUtils.java test/org/apache/commons/benchmark/TestPerformance.java
Date Sun, 13 Mar 2005 02:02:07 GMT
Author: burton
Date: Sat Mar 12 18:02:06 2005
New Revision: 157305

URL: http://svn.apache.org/viewcvs?view=rev&rev=157305
Log:
unit tests for speed

Added:
    jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestPerformance.java
Modified:
    jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMeta.java
    jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java
    jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkUtils.java

Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMeta.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMeta.java?view=diff&r1=157304&r2=157305
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMeta.java
(original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMeta.java
Sat Mar 12 18:02:06 2005
@@ -72,16 +72,6 @@
         return duration > 0 ? duration / completed : 0;
     }
 
-    public float getCompletedPerSecond() {
-
-        long meanDuration = getMeanDuration();
-
-        if ( meanDuration == 0 )
-            return 0;
-        
-        return  1000 / getMeanDuration();
-    }
-    
     public void reset() {
         started = 0;
         completed = 0;

Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java?view=diff&r1=157304&r2=157305
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java
(original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java
Sat Mar 12 18:02:06 2005
@@ -65,7 +65,8 @@
 
         buff.append( "----------------------\n" );;
         buff.append( "Results from method test: " + name + "\n" );
-        buff.append( "Total duration: " + duration + "milliseconds \n" );
+        buff.append( "Total duration: " + duration + " milliseconds \n" );
+        buff.append( "Mean duration: " + getMeanDuration() + " milliseconds \n" );
         buff.append( "Total completed: " + completed + "\n" );
         buff.append( "Total completed per second: " + getCompletedPerSecond() + "\n" );
 

Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkUtils.java?view=diff&r1=157304&r2=157305
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkUtils.java
(original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkUtils.java
Sat Mar 12 18:02:06 2005
@@ -29,7 +29,17 @@
     public static BenchmarkMethodMeta benchmarkMethod( String name ) throws Exception {
         return benchmarkMethod( name, 10 );
     }
-        
+
+    public static BenchmarkMethodMeta benchmarkMethod( String name,
+                                                       int numIterations ) throws Exception
{
+
+        String caller = Benchmark.getCallerClassname();
+
+        Class clazz = Class.forName( caller );
+
+        return benchmarkMethod( name, numIterations, clazz );
+    }
+
     /**
      * Benchmark the performance of a given method.
      * 
@@ -37,29 +47,29 @@
      * @author <a href="mailto:burton@rojo.com">Kevin A. Burton</a>
      */
     public static BenchmarkMethodMeta benchmarkMethod( String name,
-                                                       int numIterations ) throws Exception
{
+                                                       int numIterations,
+                                                       Class clazz ) throws Exception {
 
-        String caller = Benchmark.getCallerClassname();
-
-        Class clazz = Class.forName( caller );
-        
         System.gc();
 
         Method method = clazz.getMethod( name, null );
 
+        if ( method == null )
+            throw new Exception( "Unable to find method: " + method + " in class " + clazz
);
+
         BenchmarkMethodMeta bmeta = new BenchmarkMethodMeta();
         bmeta.name = name;
 
         bmeta.memoryBefore = getUsedMemory();
         long duration = 0;
 
-        for ( int i = 0; i <= numIterations; ++i ) {
+        for ( int i = 0; i < numIterations; ++i ) {
 
             long before = System.currentTimeMillis();
             
-            method.invoke( null, null );
+            method.invoke( null, new Object[0] );
 
-            if ( i == 0 )
+            if ( i == 0 && numIterations > 1 )
                 continue; //don't measure the first call
 
             long after = System.currentTimeMillis();

Added: jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestPerformance.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestPerformance.java?view=auto&rev=157305
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestPerformance.java
(added)
+++ jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestPerformance.java
Sat Mar 12 18:02:06 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.benchmark;
+
+import org.apache.commons.benchmark.*;
+import org.apache.commons.benchmark.xmlrpc.*;
+
+import org.apache.xmlrpc.*;
+
+import junit.framework.*;
+
+import java.util.*;
+
+/**
+ */
+public class TestPerformance extends TestCase {
+
+    static int TEST1_COUNT = 100000;
+
+    static Benchmark benchmark = new Benchmark();
+
+    public TestPerformance(String testName) {
+        super(testName);
+    }
+
+    public void testTransactionsPerSecond() throws Exception {
+
+        BenchmarkMethodMeta bmeta =
+            BenchmarkUtils.benchmarkMethod( "doTest1", 1, getClass() );
+
+        assertEquals( benchmark.tracker1.now.started, TEST1_COUNT );
+        assertEquals( benchmark.tracker1.now.completed, TEST1_COUNT );
+
+        double tps = ((double)TEST1_COUNT / (double)bmeta.duration) * 1000D;
+
+        assertTrue( "Not meeting minimum TPS", tps > 200000 );
+
+        //NOW disable the whole thing and trytry again.
+        Benchmark.DISABLED=true;
+
+        bmeta = BenchmarkUtils.benchmarkMethod( "doTest1", 1, getClass() );
+
+        tps = ((double)TEST1_COUNT / (double)bmeta.duration) * 1000D;
+
+        assertTrue( "Not meeting minimum TPS", tps > 5000000 );
+
+        System.out.println( bmeta.getReport() );
+        
+    }
+
+    public static void doTest1() {
+
+        for ( int i = 0; i < TEST1_COUNT; ++i ) {
+
+            benchmark.start();
+            benchmark.complete();
+            
+        }
+
+    }
+
+    public static void main( String[] args ) throws Exception {
+
+        TestPerformance test = new TestPerformance( null );
+        test.testTransactionsPerSecond();
+        
+    }
+
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message