Package edu.stanford.nlp.util
Class Timing
- java.lang.Object
-
- edu.stanford.nlp.util.Timing
-
public class Timing extends Object
A class for measuring how long things take. For backward compatibility, this class contains static methods, but the preferred usage is to instantiate a Timing object and use instance methods.To use, call
startTime()before running the code in question. Calltick()to print an intermediate update, andendTime()to finish the timing and print the result. You can optionally pass a descriptive string andPrintStreamtotickandendTimefor 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);- Author:
- Bill MacCartney
-
-
Constructor Summary
Constructors Constructor Description Timing()Constructs new Timing object and starts the timer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoing(String str)Print the start of timing message to stderr and start the timer.voiddone()Finish the line from doing() with the end of the timing done message and elapsed time in x.y seconds.voiddone(Redwood.RedwoodChannels logger, String msg)voiddone(Redwood.RedwoodChannels logger, StringBuilder msg)This method allows you to show the results of timing according to another class' logger.voiddone(String msg)Give a line saying that something is " done".voiddone(StringBuilder msg)voidend(String msg)Print the timing done message with elapsed time in x.y seconds.static voidendDoing()Finish the line from startDoing with the end of the timing done message and elapsed time in x.y seconds.static voidendDoing(String msg)Finish the line from startDoing with the end of the timing done message and elapsed time in x.y seconds.static longendTime()Return elapsed time on (static) timer (without stopping timer).static longendTime(String str)Print elapsed time on (static) timer toSystem.err(without stopping timer).static longendTime(String str, PrintStream stream)Print elapsed time on (static) timer (without stopping timer).longreport()Return elapsed time (without stopping timer).longreport(Redwood.RedwoodChannels logger, String str)Print elapsed time (without stopping timer).longreport(String str)Print elapsed time toSystem.err(without stopping timer).longreport(String str, PrintStream stream)Print elapsed time (without stopping timer).longreport(String str, PrintWriter writer)Print elapsed time (without stopping timer).longreportNano()Return elapsed time (without stopping timer).longrestart()Restart timer.longrestart(String str)Print elapsed time toSystem.errand restart timer.longrestart(String str, PrintStream stream)Print elapsed time and restart timer.longrestart(String str, PrintWriter writer)Print elapsed time and restart timer.voidstart()Start timer.static voidstartDoing(String str)Print the start of timing message to stderr and start the timer.static voidstartTime()Start (static) timer.longstop()Stop timer.longstop(String str)Print elapsed time toSystem.errand stop timer.longstop(String str, PrintStream stream)Print elapsed time and stop timer.longstop(String str, PrintWriter writer)Print elapsed time and stop timer.static longtick()Restart (static) timer.static longtick(String str)Print elapsed time toSystem.errand restart (static) timer.static longtick(String str, PrintStream stream)Print elapsed time and restart (static) timer.static StringtoMilliSecondsString(long elapsed)Format with one decimal place elapsed milliseconds.StringtoSecondsString()Returns the number of seconds passed since the timer started in the form "d.d".static StringtoSecondsString(long elapsed)Format with one decimal place elapsed milliseconds in seconds.StringtoString()
-
-
-
Method Detail
-
start
public void start()
Start timer.
-
report
public long report()
Return elapsed time (without stopping timer).- Returns:
- Number of milliseconds elapsed
-
reportNano
public long reportNano()
Return elapsed time (without stopping timer).- Returns:
- Number of nanoseconds elapsed
-
report
public long report(String str, PrintStream stream)
Print elapsed time (without stopping timer).- Parameters:
str- Additional prefix string to be printedstream- PrintStream on which to write output- Returns:
- Number of milliseconds elapsed
-
report
public long report(String str)
Print elapsed time toSystem.err(without stopping timer).- Parameters:
str- Additional prefix string to be printed- Returns:
- Number of milliseconds elapsed
-
report
public long report(Redwood.RedwoodChannels logger, String str)
Print elapsed time (without stopping timer).- Parameters:
logger- Logger to log a timed operation withstr- Additional prefix string to be printed- Returns:
- Number of milliseconds elapsed
-
report
public long report(String str, PrintWriter writer)
Print elapsed time (without stopping timer).- Parameters:
str- Additional prefix string to be printedwriter- PrintWriter on which to write output- Returns:
- Number of milliseconds elapsed
-
toSecondsString
public String toSecondsString()
Returns the number of seconds passed since the timer started in the form "d.d".
-
toSecondsString
public static String toSecondsString(long elapsed)
Format with one decimal place elapsed milliseconds in seconds.- Parameters:
elapsed- Number of milliseconds elapsed- Returns:
- Formatted String
-
toMilliSecondsString
public static String toMilliSecondsString(long elapsed)
Format with one decimal place elapsed milliseconds.- Parameters:
elapsed- Number of milliseconds elapsed- Returns:
- Formatted String
-
restart
public long restart()
Restart timer.- Returns:
- Number of milliseconds elapsed
-
restart
public long restart(String str, PrintStream stream)
Print elapsed time and restart timer.- Parameters:
str- Additional prefix string to be printedstream- PrintStream on which to write output- Returns:
- Number of milliseconds elapsed
-
restart
public long restart(String str)
Print elapsed time toSystem.errand restart timer.- Parameters:
str- Additional prefix string to be printed- Returns:
- Number of milliseconds elapsed
-
restart
public long restart(String str, PrintWriter writer)
Print elapsed time and restart timer.- Parameters:
str- Additional prefix string to be printedwriter- PrintWriter on which to write output- Returns:
- Number of milliseconds elapsed
-
end
public void end(String msg)
Print the timing done message with elapsed time in x.y seconds. Restart the timer too.
-
stop
public long stop()
Stop timer.- Returns:
- Number of milliseconds elapsed
-
stop
public long stop(String str, PrintStream stream)
Print elapsed time and stop timer.- Parameters:
str- Additional prefix string to be printedstream- PrintStream on which to write output- Returns:
- Number of milliseconds elapsed
-
stop
public long stop(String str)
Print elapsed time toSystem.errand stop timer.- Parameters:
str- Additional prefix string to be printed- Returns:
- Number of milliseconds elapsed
-
stop
public long stop(String str, PrintWriter writer)
Print elapsed time and stop timer.- Parameters:
str- Additional prefix string to be printedwriter- PrintWriter on which to write output- Returns:
- Number of milliseconds elapsed
-
startTime
public static void startTime()
Start (static) timer.
-
endTime
public static long endTime()
Return elapsed time on (static) timer (without stopping timer).- Returns:
- Number of milliseconds elapsed
-
endTime
public static long endTime(String str, PrintStream stream)
Print elapsed time on (static) timer (without stopping timer).- Parameters:
str- Additional prefix string to be printedstream- PrintStream on which to write output- Returns:
- Number of milliseconds elapsed
-
endTime
public static long endTime(String str)
Print elapsed time on (static) timer toSystem.err(without stopping timer).- Parameters:
str- Additional prefix string to be printed- Returns:
- Number of milliseconds elapsed
-
doing
public void doing(String str)
Print the start of timing message to stderr and start the timer.
-
done
public void done()
Finish the line from doing() with the end of the timing done message and elapsed time in x.y seconds.
-
done
public void done(String msg)
Give a line saying that something is " done".
-
done
public void done(StringBuilder msg)
-
done
public void done(Redwood.RedwoodChannels logger, StringBuilder msg)
This method allows you to show the results of timing according to another class' logger. E.g.,timing.done(logger, "Loading lexicon").- Parameters:
logger- Logger to log a timed operation withmsg- Message to report.
-
done
public void done(Redwood.RedwoodChannels logger, String msg)
-
startDoing
public static void startDoing(String str)
Print the start of timing message to stderr and start the timer.
-
endDoing
public static void endDoing()
Finish the line from startDoing with the end of the timing done message and elapsed time in x.y seconds.
-
endDoing
public static void endDoing(String msg)
Finish the line from startDoing with the end of the timing done message and elapsed time in x.y seconds.
-
tick
public static long tick()
Restart (static) timer.- Returns:
- Number of milliseconds elapsed
-
tick
public static long tick(String str, PrintStream stream)
Print elapsed time and restart (static) timer.- Parameters:
str- Additional prefix string to be printedstream- PrintStream on which to write output- Returns:
- Number of milliseconds elapsed
-
tick
public static long tick(String str)
Print elapsed time toSystem.errand restart (static) timer.- Parameters:
str- Additional prefix string to be printed- Returns:
- Number of milliseconds elapsed
-
-