Author: burton Date: Thu Mar 3 22:04:17 2005 New Revision: 156135 URL: http://svn.apache.org/viewcvs?view=rev&rev=156135 Log: benchmark xdocs
Added: jakarta/commons/sandbox/benchmark/trunk/xdocs/ jakarta/commons/sandbox/benchmark/trunk/xdocs/index.xml jakarta/commons/sandbox/benchmark/trunk/xdocs/navigation.xml Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java?view=diff&r1=156134&r2=156135 ============================================================================== --- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java (original) +++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/Benchmark.java Thu Mar 3 22:04:17 2005 @@ -134,16 +134,18 @@ /** * The total number of start()ed benchmarks since in the last rollover. + * @deprecated */ public long getTotalStarted() { - return tracker1.totalStarted; + return tracker1.lastStarted; } /** * The total number of complete()ed benchmarks since in the last rollover. + * @deprecated */ public long getTotalCompleted() { - return tracker1.totalCompleted; + return tracker1.lastCompleted; } /** @@ -153,6 +155,18 @@ */ public BenchmarkTracker getTracker() { return getTracker( INTERVAL_1 ); + } + + public BenchmarkTracker getTracker1() { + return tracker1.resetWhenNecessary(); + } + + public BenchmarkTracker getTracker5() { + return tracker5.resetWhenNecessary(); + } + + public BenchmarkTracker getTracker15() { + return tracker15.resetWhenNecessary(); } /** Modified: jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java?view=diff&r1=156134&r2=156135 ============================================================================== --- jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java (original) +++ jakarta/commons/sandbox/benchmark/trunk/src/java/org/apache/commons/benchmark/BenchmarkTracker.java Thu Mar 3 22:04:17 2005 @@ -19,8 +19,11 @@ import java.util.*; /** - * <p> - * Handles physically tracking each benchmark and handling rollover. + * <p> Handles physically tracking each benchmark and handling rollover. Note + * that this class is MUTABLE so if you're working with it and additional + * threads are calling start/complete the values will change. This is normally + * fine but if you're trying to perform some type of benchmark analsis then you + * shouldn't hold on to the tracker long. * * @author <a href="mailto:[EMAIL PROTECTED]">Kevin Burton</a> * @version $Id: Benchmark.java,v 1.3 2005/02/16 02:28:09 burton Exp $ @@ -49,25 +52,25 @@ /** * The current number of "started" benchmarks. This can be analyzed at - * runtime but its recommended that you use totalCompleted, totalStarted + * runtime but its recommended that you use lastCompleted, lastStarted */ public long started = 0; /** * The current number of "completed" benchmarks. This can be analyzed at - * runtime but its recommended that you use totalCompleted, totalStarted + * runtime but its recommended that you use lastCompleted, lastStarted */ public long completed = 0; /** * Value getTotalStarted */ - public long totalStarted = 0; + public long lastStarted = 0; /** * Value getTotalCompleted */ - public long totalCompleted = 0; + public long lastCompleted = 0; /** * @@ -81,8 +84,8 @@ BenchmarkTracker reset( long now ) { //need to perform a swap and save the current benchmark. - totalStarted = started; - totalCompleted = completed; + lastStarted = started; + lastCompleted = completed; //reset the benchmark timestamp = now; @@ -146,16 +149,26 @@ /** * The total number of start()ed benchmarks since in the last rollover. + * @deprecated */ public long getTotalStarted() { - return totalStarted; + return lastStarted; } /** * The total number of complete()ed benchmarks since in the last rollover. + * @deprecated */ public long getTotalCompleted() { - return totalCompleted; + return lastCompleted; + } + + public long getLastCompleted() { + return lastCompleted; + } + + public long getLastStarted() { + return lastStarted; } /** Added: jakarta/commons/sandbox/benchmark/trunk/xdocs/index.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/xdocs/index.xml?view=auto&rev=156135 ============================================================================== --- jakarta/commons/sandbox/benchmark/trunk/xdocs/index.xml (added) +++ jakarta/commons/sandbox/benchmark/trunk/xdocs/index.xml Thu Mar 3 22:04:17 2005 @@ -0,0 +1,72 @@ +<?xml version="1.0"?> +<document> + + <properties> + <author email="burton at apache.org">Kevin A. Burton</author> + <title>Overview - Commons Benchmark</title> + </properties> + + <body> + + <section name="Benchmark"> + + <p> + Benchmark that allows cheap and lightweight "benchmarking" (go + figure) of arbitrary code. All you have to do is call start() + every time a method starts which will then increment the + benchmark and perform any operations necessary to maintain the + benchmark. Just call complete() when your method is done. + </p> + + <p> + This class is lightweight (only requires a hashmap entry, and + 3x32 bytes per benchmark of storage with no external + requirements. This class is also threadsafe so if you need to + call this from multithreaded code to benchmark then you'll be + ok. + </p> + + <p> + The benchmark is maintained as number of starts and completes + per minute. This can be any type of operation you want. + Technically the interval can be longer than a minute but we will + end up with stale data. That's the tradeoff with this type of + benchmark. Its cheap and easy to maintain but anything more + than 60 seconds worth of data and you'll end up with a stale + benchmark. + </p> + + <p> + Internally we use an incremented value which is accumulated and + reset ever 60 seconds. When we reset the benchmark we reset the + current value so that we can start accumulating again. + </p> + + <source> + + Benchmark benchmark = Benchmark.getBenchmark( "foo" ); + + try { + + benchmark.start(); + + //do something expensive + + } finally { + benchmark.complete(); + } + + </source> + + <p> + The method overhead is very light. One a modern machine you can + perform about 1M benchmarks per second. For code thats only + called a few thousand times you won't notice any performance + overhead. + </p> + + </section> + + </body> + +</document> Added: jakarta/commons/sandbox/benchmark/trunk/xdocs/navigation.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/benchmark/trunk/xdocs/navigation.xml?view=auto&rev=156135 ============================================================================== --- jakarta/commons/sandbox/benchmark/trunk/xdocs/navigation.xml (added) +++ jakarta/commons/sandbox/benchmark/trunk/xdocs/navigation.xml Thu Mar 3 22:04:17 2005 @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE org.apache.commons.menus SYSTEM '../../commons-build/menus/menus.dtd'> +<project name="Benchmark"> + <title>Benchmark</title> + <body> + <menu name="Benchmark"> + + <item name="Overview" + href="/index.html" /> + + <item name="API Documentation" + href="/apidocs/index.html"/> + + <item name="Source XRef (JXR)" + href="/xref/index.html"/> + + </menu> + &common-menus; + </body> +</project> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]