Class Benchmark
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. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final Benchmark.Reporterprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionBenchmark(boolean reportingEnabled) Benchmark(boolean reportingEnabled, Benchmark.Reporter reporter) Sets up aBenchmarkwith a customBenchmark.Reporter. -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin()voidBegins a benchmark (seebegin()) and report the fact.voidbeginReporting(String message) Begins a benchmark (seebegin()) and report the fact.longend()voidEnd a benchmark (seeend()) and report the fact.voidendReporting(String message) Ends a benchmark (seebegin()) and report the fact.voidReports the given message.voidReports thetitle, a colon, a space, and the pretty-printedObject.private voidreportIndented(String message) Reports a message throughreporter, indent by N spaces where N is the current benchmark stack depth.
-
Field Details
-
beginTimes
-
reportingEnabled
private final boolean reportingEnabled -
reporter
-
PAD
- See Also:
-
-
Constructor Details
-
Benchmark
public Benchmark(boolean reportingEnabled) -
Benchmark
Sets up aBenchmarkwith a customBenchmark.Reporter.
-
-
Method Details
-
begin
public void begin()- See Also:
-
end
public long end()- See Also:
-
beginReporting
public void beginReporting()Begins a benchmark (seebegin()) and report the fact. -
beginReporting
-
endReporting
public void endReporting()End a benchmark (seeend()) and report the fact. -
endReporting
-
report
Reports the given message. -
report
-
reportIndented
-