Package com.day.util
Class Timing
java.lang.Object
com.day.util.Timing
The
Timing class supports timing code fragments. A timer has a
name, which may be used for informational purposes, and a start time against
which the elapsed time is calculated.
The start time is first set to the time of instance creation and may later
be set to the current time using the reset() method. The name of the
timer is also set at instance creation time and may be changed using the
setName(java.lang.String) method.
The time elapsed since the last timer reset (either instance creation or
call to the reset() method) is accessible through the
getElapsed() and may be logged using the stamp(java.lang.String) method.
- Since:
- gumbaer
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTiming()Creates an instance with thedefault name.Creates an instance with the given name. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the time in milliseconds elapsed since the starting time.getName()Returns the name of this instance.longReturns the starting time of this instance.voidreset()Resets the starting time of this instance to the current system time.voidSets the name of this instance.voidWrites the elapsed time to the timer log.toString()Returns a string representation of this instance, which consists of the name and human readable form of the start time.
-
Field Details
-
DEFAULT_NAME
The defualt name for instances- See Also:
-
-
Constructor Details
-
Timing
public Timing()Creates an instance with thedefault name. The start time of the new instance is set to the time of instance creation.Calling this method is equivalent to calling
new Timing(null)- See Also:
-
Timing
Creates an instance with the given name. The start time of the new instance is set to the time of instance creation.- Parameters:
name- The name of the new instance. If the name is empty ornull, the name will be set to thedefault name.
-
-
Method Details
-
getName
Returns the name of this instance.- Returns:
- The name of this instance.
-
setName
Sets the name of this instance.- Parameters:
name- The new name to set on this instance. If the name is empty ornull, the name will be set to thedefault name.
-
getStartTime
public long getStartTime()Returns the starting time of this instance.- Returns:
- the start time
- See Also:
-
reset
public void reset()Resets the starting time of this instance to the current system time.- See Also:
-
getElapsed
public long getElapsed()Returns the time in milliseconds elapsed since the starting time.- Returns:
- the elapsed time
- See Also:
-
stamp
Writes the elapsed time to the timer log. The message contains the timer name, the supplied message and the elapsed time in milliseconds.The log message is logged as an informational message at level
INFOto the loggermisc.timing.- Parameters:
message- The message to be added to the log message.
-
toString
Returns a string representation of this instance, which consists of the name and human readable form of the start time.
-