public class Benchmark extends Object
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Benchmark.Reporter
Interface used to report messages.
|
| Constructor and Description |
|---|
Benchmark(boolean reportingEnabled)
|
Benchmark(boolean reportingEnabled,
Benchmark.Reporter reporter)
Sets up a
Benchmark with a custom Benchmark.Reporter. |
| Modifier and Type | Method and Description |
|---|---|
void |
begin() |
void |
beginReporting()
Begins a benchmark (see
begin()) and report the fact. |
void |
beginReporting(String message)
Begins a benchmark (see
begin()) and report the fact. |
long |
end() |
void |
endReporting()
End a benchmark (see
end()) and report the fact. |
void |
endReporting(String message)
Ends a benchmark (see
begin()) and report the fact. |
void |
report(String message)
Reports the given message.
|
void |
report(String optionalTitle,
Object o)
Reports the
title, a colon, a space, and the pretty-printed Object. |
public Benchmark(boolean reportingEnabled)
public Benchmark(boolean reportingEnabled,
Benchmark.Reporter reporter)
Benchmark with a custom Benchmark.Reporter.public void begin()
Benchmarkpublic long end()
Benchmarkpublic void beginReporting()
begin()) and report the fact.public void beginReporting(String message)
begin()) and report the fact.public void endReporting()
end()) and report the fact.public void endReporting(String message)
begin()) and report the fact.public void report(String message)
Copyright © 2019. All rights reserved.