Package org.codehaus.janino.util
Class Benchmark
java.lang.Object
org.codehaus.janino.util.Benchmark
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 Benchmark.Reporter object. The default
Benchmark.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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface used to report messages. -
Constructor Summary
ConstructorsConstructorDescriptionBenchmark(boolean reportingEnabled) Benchmark(boolean reportingEnabled, Benchmark.Reporter reporter) Set up aBenchmarkwith a customBenchmark.Reporter. -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()voidBegin a benchmark (seebegin()) and report the fact.voidbeginReporting(String message) Begin a benchmark (seebegin()) and report the fact.longend()voidEnd a benchmark (seeend()) and report the fact.voidendReporting(String message) End a benchmark (seebegin()) and report the fact.voidReport the given message.voidReport thetitle, a colon, a space, and the pretty-printedObject.
-
Constructor Details
-
Benchmark
public Benchmark() -
Benchmark
public Benchmark(boolean reportingEnabled) -
Benchmark
Set up aBenchmarkwith a customBenchmark.Reporter.
-
-
Method Details
-
begin
public void begin()- See Also:
-
end
public long end()- See Also:
-
beginReporting
public void beginReporting()Begin a benchmark (seebegin()) and report the fact. -
beginReporting
Begin a benchmark (seebegin()) and report the fact. -
endReporting
public void endReporting()End a benchmark (seeend()) and report the fact. -
endReporting
End a benchmark (seebegin()) and report the fact. -
report
Report the given message. -
report
Report thetitle, a colon, a space, and the pretty-printedObject.- Parameters:
optionalTitle-o-
-