commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bur...@apache.org
Subject svn commit: r157289 - in jakarta/commons/sandbox/benchmark/trunk/src: java/org/apache/commons/benchmark/ test/org/apache/commons/benchmark/
Date Sat, 12 Mar 2005 22:43:43 GMT
Author: burton
Date: Sat Mar 12 14:43:41 2005
New Revision: 157289

URL: http://svn.apache.org/viewcvs?view=rev&rev=157289
Log:
Refactored a bit.  Adding a string and two longs increase the benchmark by 140 bytes which
isn't acceptable.

Added:
    jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java
    jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestBenchmarkUtils.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/BenchmarkUtils.java
    jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.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=157288&r2=157289
==============================================================================
--- 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 14:43:41 2005
@@ -32,18 +32,6 @@
     public long completed = 0;
 
     public long duration = 0;
-
-    /**
-     * The name of this metadata result (optional)
-     */
-    public String name = null;
-
-    /**
-     * Track the total amount of memory available BEFORE this benchmark.  -1 if
-     * not available.  
-     */
-    public long memoryBefore = -1;
-    public long memoryAfter = -1;
     
     /**
      * The time the current benchmark was started.  -1 for never started.
@@ -98,32 +86,6 @@
         started = 0;
         completed = 0;
         duration = 0;
-    }
-
-    /**
-     * Build a human readable report from the benchmark.  This should include
-     * information such as mean duration, memory used, etc.
-     *
-     * @author <a href="mailto:burton@rojo.com">Kevin A. Burton</a>
-     */
-    public String getReport() {
-
-        StringBuffer buff = new StringBuffer();
-
-        buff.append( "----------------------\n" );;
-        buff.append( "Results from method test: " + name + "\n" );
-        buff.append( "Total duration: " + duration + "milliseconds \n" );
-        buff.append( "Total completed: " + completed + "\n" );
-        buff.append( "Total completed per second: " + getCompletedPerSecond() + "\n" );
-
-        if ( memoryBefore > -1 ) {
-
-            buff.append( "Used memory: "  + (memoryAfter-memoryBefore) + "\n" );
-
-        }
-        
-        return buff.toString();
-
     }
     
 }

Added: 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=auto&rev=157289
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java
(added)
+++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkMethodMeta.java
Sat Mar 12 14:43:41 2005
@@ -0,0 +1,82 @@
+/*
+ * 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;
+
+/**
+ * Used to represent metadata for a benchmark including name, timestamp,
+ * started, completed, etc.
+ * 
+ * @author <a href="mailto:burton@rojo.com">Kevin Burton</a>
+ * @version $Id: Benchmark.java,v 1.3 2005/02/16 02:28:09 burton Exp $
+ */
+public class BenchmarkMethodMeta extends BenchmarkMeta{
+
+    /**
+     * The name of this metadata result (optional)
+     */
+    public String name = null;
+
+    /**
+     * Track the total amount of memory available BEFORE this benchmark.  -1 if
+     * not available.  
+     */
+    public long memoryBefore = -1;
+    public long memoryAfter = -1;
+
+    public float getCompletedPerSecond() {
+
+        long meanDuration = getMeanDuration();
+
+        if ( meanDuration == 0 )
+            return 0;
+        
+        return  1000 / getMeanDuration();
+    }
+    
+    public void reset() {
+        started = 0;
+        completed = 0;
+        duration = 0;
+    }
+
+    /**
+     * Build a human readable report from the benchmark.  This should include
+     * information such as mean duration, memory used, etc.
+     *
+     * @author <a href="mailto:burton@rojo.com">Kevin A. Burton</a>
+     */
+    public String getReport() {
+
+        StringBuffer buff = new StringBuffer();
+
+        buff.append( "----------------------\n" );;
+        buff.append( "Results from method test: " + name + "\n" );
+        buff.append( "Total duration: " + duration + "milliseconds \n" );
+        buff.append( "Total completed: " + completed + "\n" );
+        buff.append( "Total completed per second: " + getCompletedPerSecond() + "\n" );
+
+        if ( memoryBefore > -1 ) {
+
+            buff.append( "Used memory: "  + (memoryAfter-memoryBefore) + "\n" );
+
+        }
+        
+        return buff.toString();
+
+    }
+    
+}

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=157288&r2=157289
==============================================================================
--- 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 14:43:41 2005
@@ -26,7 +26,7 @@
  */
 public class BenchmarkUtils {
 
-    public static BenchmarkMeta benchmarkMethod( String name ) throws Exception {
+    public static BenchmarkMethodMeta benchmarkMethod( String name ) throws Exception {
         return benchmarkMethod( name, 10 );
     }
         
@@ -36,8 +36,8 @@
      * @param name The name of the method from the caller (found via reflection).
      * @author <a href="mailto:burton@rojo.com">Kevin A. Burton</a>
      */
-    public static BenchmarkMeta benchmarkMethod( String name,
-                                                 int numIterations ) throws Exception {
+    public static BenchmarkMethodMeta benchmarkMethod( String name,
+                                                       int numIterations ) throws Exception
{
 
         String caller = Benchmark.getCallerClassname();
 
@@ -47,7 +47,7 @@
 
         Method method = clazz.getMethod( name, null );
 
-        BenchmarkMeta bmeta = new BenchmarkMeta();
+        BenchmarkMethodMeta bmeta = new BenchmarkMethodMeta();
         bmeta.name = name;
 
         bmeta.memoryBefore = getUsedMemory();

Modified: jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java?view=diff&r1=157288&r2=157289
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
(original)
+++ jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/Test1.java
Sat Mar 12 14:43:41 2005
@@ -160,7 +160,9 @@
         //references to strings?
         long usedMemory = after - before;
         System.out.println( "Total bytes used by benchmark: " + usedMemory );
-        assertTrue( usedMemory < 500 * count );
+        if ( false == usedMemory < 500 * count ) {
+            throw new Exception( "used memory too large: " + usedMemory / count + " bytes
per metric" );
+        }
 
         resetForTests();
         //Benchmark.benchmarks.clear();

Added: jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestBenchmarkUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestBenchmarkUtils.java?view=auto&rev=157289
==============================================================================
--- jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestBenchmarkUtils.java
(added)
+++ jakarta/commons/sandbox/benchmark/trunk/src/test/org/apache/commons/benchmark/TestBenchmarkUtils.java
Sat Mar 12 14:43:41 2005
@@ -0,0 +1,41 @@
+/*
+ * 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 TestBenchmarkUtils extends TestCase {
+
+    public TestBenchmarkUtils(String testName) {
+        super(testName);
+    }
+
+    public void test1() {
+
+    }
+    
+}
+



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