public class Timing
extends java.lang.Object
To use, call startTime()
before running the code in
question. Call tick()
to print an intermediate update, and endTime()
to
finish the timing and print the result. You can optionally pass a descriptive
string and PrintStream
to tick
and endTime
for more control over what gets printed where.
Example: time reading in a big file and transforming it:
Timing.startTime();
String bigFileContents = IOUtils.slurpFile(bigFile);
Timing.tick("read in big file", System.err);
String output = costlyTransform(bigFileContents);
Timing.endTime("transformed big file", System.err);
Constructor and Description |
---|
Timing()
Constructs new Timing object and starts the timer.
|
Modifier and Type | Method and Description |
---|---|
void |
doing(java.lang.String str)
Print the start of timing message to stderr and start the timer.
|
void |
done()
Finish the line from doing() with the end of the timing done message
and elapsed time in x.y seconds.
|
void |
done(Redwood.RedwoodChannels logger,
java.lang.String msg) |
void |
done(Redwood.RedwoodChannels logger,
java.lang.StringBuilder msg)
This method allows you to show the results of timing according to another class' logger.
|
void |
done(java.lang.String msg)
Give a line saying that something is " done".
|
void |
done(java.lang.StringBuilder msg) |
void |
end(java.lang.String msg)
Print the timing done message with elapsed time in x.y seconds.
|
static void |
endDoing()
Finish the line from startDoing with the end of the timing done message
and elapsed time in x.y seconds.
|
static void |
endDoing(java.lang.String msg)
Finish the line from startDoing with the end of the timing done message
and elapsed time in x.y seconds.
|
static long |
endTime()
Return elapsed time on (static) timer (without stopping timer).
|
static long |
endTime(java.lang.String str)
Print elapsed time on (static) timer to
System.err (without stopping timer). |
static long |
endTime(java.lang.String str,
java.io.PrintStream stream)
Print elapsed time on (static) timer (without stopping timer).
|
long |
report()
Return elapsed time (without stopping timer).
|
long |
report(Redwood.RedwoodChannels logger,
java.lang.String str)
Print elapsed time (without stopping timer).
|
long |
report(java.lang.String str)
Print elapsed time to
System.err (without stopping timer). |
long |
report(java.lang.String str,
java.io.PrintStream stream)
Print elapsed time (without stopping timer).
|
long |
report(java.lang.String str,
java.io.PrintWriter writer)
Print elapsed time (without stopping timer).
|
long |
reportNano()
Return elapsed time (without stopping timer).
|
long |
restart()
Restart timer.
|
long |
restart(java.lang.String str)
Print elapsed time to
System.err and restart timer. |
long |
restart(java.lang.String str,
java.io.PrintStream stream)
Print elapsed time and restart timer.
|
long |
restart(java.lang.String str,
java.io.PrintWriter writer)
Print elapsed time and restart timer.
|
void |
start()
Start timer.
|
static void |
startDoing(java.lang.String str)
Print the start of timing message to stderr and start the timer.
|
static void |
startTime()
Start (static) timer.
|
long |
stop()
Stop timer.
|
long |
stop(java.lang.String str)
Print elapsed time to
System.err and stop timer. |
long |
stop(java.lang.String str,
java.io.PrintStream stream)
Print elapsed time and stop timer.
|
long |
stop(java.lang.String str,
java.io.PrintWriter writer)
Print elapsed time and stop timer.
|
static long |
tick()
Restart (static) timer.
|
static long |
tick(java.lang.String str)
Print elapsed time to
System.err and restart (static) timer. |
static long |
tick(java.lang.String str,
java.io.PrintStream stream)
Print elapsed time and restart (static) timer.
|
static java.lang.String |
toMilliSecondsString(long elapsed)
Format with one decimal place elapsed milliseconds.
|
java.lang.String |
toSecondsString()
Returns the number of seconds passed since the timer started in the form "d.d".
|
static java.lang.String |
toSecondsString(long elapsed)
Format with one decimal place elapsed milliseconds in seconds.
|
java.lang.String |
toString() |
public void start()
public long report()
public long reportNano()
public long report(java.lang.String str, java.io.PrintStream stream)
str
- Additional prefix string to be printedstream
- PrintStream on which to write outputpublic long report(java.lang.String str)
System.err
(without stopping timer).str
- Additional prefix string to be printedpublic long report(Redwood.RedwoodChannels logger, java.lang.String str)
logger
- Logger to log a timed operation withstr
- Additional prefix string to be printedpublic long report(java.lang.String str, java.io.PrintWriter writer)
str
- Additional prefix string to be printedwriter
- PrintWriter on which to write outputpublic java.lang.String toSecondsString()
public static java.lang.String toSecondsString(long elapsed)
elapsed
- Number of milliseconds elapsedpublic static java.lang.String toMilliSecondsString(long elapsed)
elapsed
- Number of milliseconds elapsedpublic long restart()
public long restart(java.lang.String str, java.io.PrintStream stream)
str
- Additional prefix string to be printedstream
- PrintStream on which to write outputpublic long restart(java.lang.String str)
System.err
and restart timer.str
- Additional prefix string to be printedpublic long restart(java.lang.String str, java.io.PrintWriter writer)
str
- Additional prefix string to be printedwriter
- PrintWriter on which to write outputpublic void end(java.lang.String msg)
public long stop()
public long stop(java.lang.String str, java.io.PrintStream stream)
str
- Additional prefix string to be printedstream
- PrintStream on which to write outputpublic long stop(java.lang.String str)
System.err
and stop timer.str
- Additional prefix string to be printedpublic long stop(java.lang.String str, java.io.PrintWriter writer)
str
- Additional prefix string to be printedwriter
- PrintWriter on which to write outputpublic static void startTime()
public static long endTime()
public static long endTime(java.lang.String str, java.io.PrintStream stream)
str
- Additional prefix string to be printedstream
- PrintStream on which to write outputpublic static long endTime(java.lang.String str)
System.err
(without stopping timer).str
- Additional prefix string to be printedpublic void doing(java.lang.String str)
public void done()
public void done(java.lang.String msg)
public void done(java.lang.StringBuilder msg)
public void done(Redwood.RedwoodChannels logger, java.lang.StringBuilder msg)
timing.done(logger, "Loading lexicon")
.logger
- Logger to log a timed operation withmsg
- Message to report.public void done(Redwood.RedwoodChannels logger, java.lang.String msg)
public static void startDoing(java.lang.String str)
public static void endDoing()
public static void endDoing(java.lang.String msg)
public static long tick()
public static long tick(java.lang.String str, java.io.PrintStream stream)
str
- Additional prefix string to be printedstream
- PrintStream on which to write outputpublic static long tick(java.lang.String str)
System.err
and restart (static) timer.str
- Additional prefix string to be printedpublic java.lang.String toString()
toString
in class java.lang.Object