类 StopWatch
Conceals use of System.nanoTime(), improving the readability of
application code and reducing the likelihood of calculation errors.
Note that this object is not designed to be thread-safe and does not use synchronization.
This class is normally used to verify performance during proof-of-concept work and in development, rather than as part of production applications.
- 从以下版本开始:
- 3.0
- 作者:
- Rod Johnson, Juergen Hoeller, Sam Brannen, TODAY 2021/2/4 11:26
-
嵌套类概要
嵌套类修饰符和类型类说明static final classNested class to hold data about one task executed within theStopWatch. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明Get the name of the currently running task, if any.getId()Get the ID of thisStopWatch, as specified on construction.Get the last task as aStopWatch.TaskInfoobject.Get the name of the last task.longGet the time taken by the last task in milliseconds.longGet the time taken by the last task in nanoseconds.intGet the number of tasks timed.Get an array of the data for tasks performed.longGet the total time in milliseconds for all tasks.longGet the total time in nanoseconds for all tasks.doubleGet the total time in seconds for all tasks.booleanDetermine whether thisStopWatchis currently running.Generate a string with a table describing all tasks performed.voidsetKeepTaskList(boolean keepTaskList) Configure whether theStopWatch.TaskInfoarray is built over time.Get a short description of the total running time.voidstart()Start an unnamed task.voidStart a named task.voidstop()Stop the current task.toString()Generate an informative string describing all tasks performed
-
构造器详细资料
-
StopWatch
public StopWatch()Construct a newStopWatch.Does not start any task.
-
StopWatch
Construct a newStopWatchwith the given ID.The ID is handy when we have output from multiple stop watches and need to distinguish between them.
Does not start any task.
- 参数:
id- identifier for this stop watch
-
-
方法详细资料
-
getId
Get the ID of thisStopWatch, as specified on construction.- 返回:
- the ID (empty String by default)
- 另请参阅:
-
setKeepTaskList
public void setKeepTaskList(boolean keepTaskList) Configure whether theStopWatch.TaskInfoarray is built over time.Set this to
falsewhen using aStopWatchfor millions of intervals; otherwise, theTaskInfostructure will consume excessive memory.Default is
true. -
start
Start an unnamed task.The results are undefined if
stop()or timing methods are called without invoking this method first.- 抛出:
IllegalStateException- 另请参阅:
-
start
Start a named task.The results are undefined if
stop()or timing methods are called without invoking this method first.- 参数:
taskName- the name of the task to start- 抛出:
IllegalStateException- 另请参阅:
-
stop
Stop the current task.The results are undefined if timing methods are called without invoking at least one pair of
start()/stop()methods.- 抛出:
IllegalStateException- 另请参阅:
-
isRunning
public boolean isRunning()Determine whether thisStopWatchis currently running.- 另请参阅:
-
currentTaskName
Get the name of the currently running task, if any.- 另请参阅:
-
getLastTaskTimeNanos
Get the time taken by the last task in nanoseconds.- 抛出:
IllegalStateException- 另请参阅:
-
getLastTaskTimeMillis
Get the time taken by the last task in milliseconds.- 抛出:
IllegalStateException- 另请参阅:
-
getLastTaskName
Get the name of the last task. -
getLastTaskInfo
Get the last task as aStopWatch.TaskInfoobject. -
getTotalTimeNanos
public long getTotalTimeNanos()Get the total time in nanoseconds for all tasks. -
getTotalTimeMillis
public long getTotalTimeMillis()Get the total time in milliseconds for all tasks. -
getTotalTimeSeconds
public double getTotalTimeSeconds()Get the total time in seconds for all tasks. -
getTaskCount
public int getTaskCount()Get the number of tasks timed. -
getTaskInfo
Get an array of the data for tasks performed. -
shortSummary
Get a short description of the total running time. -
prettyPrint
Generate a string with a table describing all tasks performed.For custom reporting, call
getTaskInfo()and use the task info directly. -
toString
Generate an informative string describing all tasks performedFor custom reporting, call
getTaskInfo()and use the task info directly.
-