|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ecyrd.speed4j.StopWatch
public class StopWatch
Creates a simple StopWatch with nanosecond precision (though not necessarily accuracy).
A "tag" is an unique grouping identifier. A "message" can be anything you like; it just travels with the StopWatch and is output with the toString method.
Tags must not contain whitespace, forward slash or commas. All other characters are allowed.
Most of the StopWatch methods return a reference to itself for easy chaining.
| Constructor Summary | |
|---|---|
StopWatch()
|
|
StopWatch(String tag)
|
|
StopWatch(String tag,
String message)
|
|
| Method Summary | |
|---|---|
StopWatch |
freeze()
Returns a cloned, freezed copy of the StopWatch. |
long |
getCreationTime()
Returns the moment in time at which this StopWatch was created (milliseconds since EPOCH). |
String |
getMessage()
Returns the message associated with this StopWatch. |
String |
getTag()
Returns the tag (grouping) for this StopWatch. |
long |
getTimeNanos()
Returns the elapsed time in nanoseconds. |
protected void |
internalStop()
The internal stop() method, which can be overridden by subclasses to provide additional functionality at stop(). |
StopWatch |
lap()
Stops and starts the StopWatch, essentially resetting it. |
StopWatch |
start()
Starts a StopWatch which has been previously stopped. |
StopWatch |
stop()
Stops the StopWatch. |
StopWatch |
stop(String tag)
Stops the StopWatch and assigns the given tag to it. |
StopWatch |
stop(String tag,
String message)
Stops the StopWatch, assigns the tag and a free-form message. |
String |
toString()
Returns a human-readable string. |
String |
toString(int iterations)
Returns a human readable string which also calculates the speed of a single operation. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public StopWatch()
public StopWatch(String tag)
public StopWatch(String tag,
String message)
| Method Detail |
|---|
public StopWatch start()
protected void internalStop()
public StopWatch stop()
public StopWatch stop(String tag)
tag - The tag to assign.
public StopWatch stop(String tag,
String message)
tag - The tag to assign.message - A free-form message that associates with this particular StopWatch.
public StopWatch lap()
public String getMessage()
public String getTag()
public long getTimeNanos()
public long getCreationTime()
public String toString()
toString in class Objectpublic String toString(int iterations)
StopWatch sw = ...
for( int i = 0; i < 1000; i++ )
{
// Do something
}
sw.stop("test");
System.out.println( sw.toString(1000) );
This might print out something like:
test: 14520 ms (68 iterations/second)
iterations -
public StopWatch freeze()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||