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
Benchmark.begin() and later calling
Benchmark.end() whichs
returns the time elapsed since the call to
Benchmark.begin() .
Notice that calls to
Benchmark.begin() and
Benchmark.end() can be nested, and each call to
Benchmark.end() refers to the matching
Benchmark.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
Benchmark.begin() /
Benchmark.end() pairs.
The pair
Benchmark.beginReporting() and
Benchmark.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.Benchmark(boolean) with a true argument.
|