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.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Benchmark.Reporter
Interface used to report messages. |
| Modifier and Type | Field and Description |
|---|---|
| private final Stack | |
| private static final String | |
| private final Benchmark. | |
| private final boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | |
| public long | |
| public void | |
| public void | |
| public void | |
| public void | |
| private void | reportIndented(String message)
Reports a message through |
| beginTimes | back to summary |
|---|---|
| private final Stack<Long> beginTimes | |
| PAD | back to summary |
|---|---|
| private static final String PAD | |
| reporter | back to summary |
|---|---|
| private final Benchmark. | |
| reportingEnabled | back to summary |
|---|---|
| private final boolean reportingEnabled | |
| Benchmark | back to summary |
|---|---|
| public Benchmark(boolean reportingEnabled) Sets up a | |
| Benchmark | back to summary |
|---|---|
| public Benchmark(boolean reportingEnabled, Benchmark. | |
| begin | back to summary |
|---|---|
public void begin()
| |
| beginReporting | back to summary |
|---|---|
| public void beginReporting() Begins a benchmark (see | |
| beginReporting | back to summary |
|---|---|
| public void beginReporting(String message) Begins a benchmark (see | |
| end | back to summary |
|---|---|
public long end()
| |
| endReporting | back to summary |
|---|---|
| public void endReporting() End a benchmark (see | |
| endReporting | back to summary |
|---|---|
| public void endReporting(String message) Ends a benchmark (see | |
| report | back to summary |
|---|---|
| public void report(String message) Reports the given message. | |
| report | back to summary |
|---|---|
| public void report(String title, Object o) Reports the | |
| reportIndented | back to summary |
|---|---|
| private void reportIndented(String message) Reports a message through | |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| report | back to summary |
|---|---|
| public void report(String message) Reports the given message. | |