Top Description Inners Fields Constructors Methods
org.codehaus.commons.compiler.util

public Class Benchmark

extends Object
Class Inheritance
Imports
java.util.Stack, org.codehaus.commons.nullanalysis.Nullable

Implements a scheme for benchmarking, i.e. for determining and/or reporting the time elapsed between the beginning and the end of an activity.

The measurement is done by invoking begin() and later calling end() whichs returns the time elapsed since the call to begin().

Notice that calls to begin() and end() can be nested, and each call to end() refers to the matching begin() call. To ensure that all calls match, the preferred way to write a benchmark is

...
Benchmark b = new Benchmark();
...
b.begin();
try {
    ....
} finally {
    long ms = b.end();
}

This code layout also makes it visually easy to write correct pairs of begin() / end() pairs.

The pair beginReporting() and endReporting() do basically the same, but report the benchmarking information through an internal Reporter object. The default Reporter prints its messages by System.out.println().

Reporting is only enabled if the Benchmark object was created through Benchmark(boolean) with a true argument.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Benchmark.Reporter

Interface used to report messages.

Field Summary

Modifier and TypeField and Description
private final Stack<Long>
private static final String
private final Benchmark.Reporter
private final boolean

Constructor Summary

AccessConstructor and Description
public
Benchmark(boolean reportingEnabled)

Sets up a Benchmark with a default Reporter that reports to System.out.

public
Benchmark(boolean reportingEnabled, Benchmark.Reporter reporter)

Sets up a Benchmark with a custom Reporter.

Method Summary

Modifier and TypeMethod and Description
public void
public void
beginReporting()

Begins a benchmark (see begin()) and report the fact.

public void
beginReporting(String message)

Begins a benchmark (see begin()) and report the fact.

public long
end()

public void
endReporting()

End a benchmark (see end()) and report the fact.

public void
endReporting(String message)

Ends a benchmark (see begin()) and report the fact.

public void
report(String message)

Reports the given message.

public void
report(String title, Object o)

Reports the title, a colon, a space, and the pretty-printed Object.

private void
reportIndented(String message)

Reports a message through reporter, indent by N spaces where N is the current benchmark stack depth.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beginTimesback to summary
private final Stack<Long> beginTimes
PADback to summary
private static final String PAD
reporterback to summary
private final Benchmark.Reporter reporter
reportingEnabledback to summary
private final boolean reportingEnabled

Constructor Detail

Benchmarkback to summary
public Benchmark(boolean reportingEnabled)

Sets up a Benchmark with a default Reporter that reports to System.out.

Benchmarkback to summary
public Benchmark(boolean reportingEnabled, Benchmark.Reporter reporter)

Sets up a Benchmark with a custom Reporter.

Method Detail

beginback to summary
public void begin()
See Also
Benchmark
beginReportingback to summary
public void beginReporting()

Begins a benchmark (see begin()) and report the fact.

beginReportingback to summary
public void beginReporting(String message)

Begins a benchmark (see begin()) and report the fact.

endback to summary
public long end()
See Also
Benchmark
endReportingback to summary
public void endReporting()

End a benchmark (see end()) and report the fact.

endReportingback to summary
public void endReporting(String message)

Ends a benchmark (see begin()) and report the fact.

reportback to summary
public void report(String message)

Reports the given message.

reportback to summary
public void report(String title, Object o)

Reports the title, a colon, a space, and the pretty-printed Object.

reportIndentedback to summary
private void reportIndented(String message)

Reports a message through reporter, indent by N spaces where N is the current benchmark stack depth.

org.codehaus.commons.compiler.util back to summary

public Interface Benchmark.Reporter


Interface used to report messages.

Method Summary

Modifier and TypeMethod and Description
public void
report(String message)

Reports the given message.

Method Detail

reportback to summary
public void report(String message)

Reports the given message.