public class Timing
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static org.mitre.poorMan.javaTiming.LogTarget |
logTarget |
static double |
startStopOverhead |
static java.lang.String |
TIME_FORMAT
The format used to output absolute time: "%1$TH:%1$TM:%1$TS.%1$TL"
The format can be changed at runtime.
|
Modifier and Type | Method and Description |
---|---|
static double |
adjustedAvg(StopWatch sw)
Convenience method that subtracts the estimated start/stop overhead
from the stop watch's average.
|
static void |
clearAll()
Clear timers and statistics.
|
static void |
clearAll(java.lang.String message)
Clear timers and statistics and write out a message.
|
static void |
clearAllTersely(java.lang.String message)
Clear timers and statistics and write out a message
Don't warn if there are no registered timings.
|
static MemoryWatch |
createMemoryWatch(java.lang.String name)
Create a MemoryWatch and register it.
|
static StopWatch |
createStopWatch(java.lang.String name)
Create a StopWatch and register it.
|
static long |
determineNanosecondGranularity()
This will determine the granularity of your system's
nanosecond clock by "spinning" in a loop looking for
rollover in the time reported by System.nanoTime().
|
static Statistic |
determineNanosecondJitterMinMax()
This will get 1000 successive readings
from the nanosecond clock to compute its statistics.
|
static java.lang.Object |
dumpTimings(java.lang.String message)
Dump all registered timings to the log.
|
static double |
estimateStartStopOverhead()
Iteratively (100,000 times) invokes StopWatch.start() followed by StopWatch.stop() to
determine the average overhead for these calls.
|
static double |
estimateStartStopOverhead(StopWatch sw)
Iteratively (100,000 times) invokes sw.start() followed by sw.stop() to
determine the average overhead for these calls.
|
static java.lang.String |
formattedCurrentTime()
Returns the current time in the current time format.
|
static java.lang.String |
formattedCurrentTime(long time)
Returns the specified time in the current time format.
|
static void |
memoryLog(java.lang.Object o)
Sometimes you want to add notes to the output log without incurring the overhead
of I/O at the time.
|
static void |
pause(long millis)
A convenience method to sleep for the specified time
|
static void |
printP(java.lang.Object o)
Logs the message by invoking o.toString() and adds the time to the end of the line using
the
TIME_FORMAT format. |
static void |
printP(java.lang.String msg)
Logs the message and adds the current time to the end of the line using
the
TIME_FORMAT format. |
static void |
printP(java.lang.String msg,
long time)
Logs the message and adds the time to the end of the line using
the
TIME_FORMAT format. |
static void |
registerDerivedComputation(java.lang.String name,
DerivedComputation computation)
Register a DerivedComputation.
|
static void |
setStopWatchFactory(StopWatchFactory factory)
Replaces the default factory with your own.
|
static void |
stopStart(StopWatch timeToStop,
StopWatch timeToStart)
This ensures that the same time is used
to stop a previous timer and restart another one.
|
static void |
stripBaseName(java.lang.String baseName)
Base names are stripped from the output generated by dumpTimings() to
clean up the output of redundant text.
|
static void |
summarizeAverageFirstByDefault()
Set the default summary for new stop watches.
|
static void |
summarizeCumulativeFirstByDefault()
Set the default summary for new stop watches.
|
public static double startStopOverhead
public static org.mitre.poorMan.javaTiming.LogTarget logTarget
public static java.lang.String TIME_FORMAT
public static double adjustedAvg(StopWatch sw)
sw
- java.lang.IllegalStateException
- if the average is less than the overheadpublic static void summarizeCumulativeFirstByDefault()
Watch.summarize()
to first show the
cumulative, then the average.public static void summarizeAverageFirstByDefault()
Watch.summarize()
to first show the average
then the cumulative.public static void clearAll()
public static void clearAll(java.lang.String message)
public static void clearAllTersely(java.lang.String message)
public static MemoryWatch createMemoryWatch(java.lang.String name)
The difference between createMemoryWatch() and createMemoryStatistic() is that the former reports cumulative memory in the output and the number of iterations. The latter reports average time as well as other statistics. Unlike time, memory usage can be negative if the garbage collector reclaims memory. Thus the average may be zero though the variance could be big.
Beware that a MemoryWatch is identified by its name
. If you
call this method more than once with the same name the MemoryWatch that is
returned will be the same!
The idea is to conditionally compile the logic so you can essentially remove it from the runtime when you are not debugging.
Typical code would be:
static final boolean WATCH_MEMORY = true; MemoryWatch myMem = null; ... if (WATCH_MEMORY) { if (myMem == null){ myMem = Timing.createAndRegister("memory usage"); } myMem.start(); } .... work done here ... if (WATCH_MEMORY) { myMem.stop(); }
java.lang.IllegalStateException
- if a StopWatch with the same name has already been created.public static StopWatch createStopWatch(java.lang.String name)
Once created a StopWatch can be turned into a statistic by invoking its enableStdDev() method. Then it will report average time and standard deviation.
Beware that a StopWatch is identified by its name
. If you
call this method more than once with the same name the StopWatch that is
returned will be the same!
The idea is to conditionally compile the timing logic so you can essentially remove it from the runtime when you are not debugging.
Typical code would be:
static final boolean DO_TIMING = true; StopWatch myTiming = null; ... if (DO_TIMING) { if (myTiming == null){ myTiming = Timing.createAndRegister("start of my task"); } myTiming.start(); } .... work done here ... if (DO_TIMING) { myTiming.stop(); }
java.lang.IllegalStateException
- if there is a MemoryWatch with the same name.public static long determineNanosecondGranularity()
public static Statistic determineNanosecondJitterMinMax()
Statistic
in nanoseconds.public static java.lang.Object dumpTimings(java.lang.String message)
public static double estimateStartStopOverhead()
public static double estimateStartStopOverhead(StopWatch sw)
sw
- the StopWatch to usepublic static java.lang.String formattedCurrentTime()
TIME_FORMAT
public static java.lang.String formattedCurrentTime(long time)
TIME_FORMAT
public static void memoryLog(java.lang.Object o)
o
- Object to invoke toString()
onpublic static void pause(long millis)
millis
- public static void printP(java.lang.Object o)
TIME_FORMAT
format.public static void printP(java.lang.String msg)
TIME_FORMAT
format.public static void printP(java.lang.String msg, long time)
TIME_FORMAT
format.msg
- time
- public static void registerDerivedComputation(java.lang.String name, DerivedComputation computation)
dumpTimings()
is invoked.name
- Used as part of the output.computation
- The DerivedComputationpublic static void setStopWatchFactory(StopWatchFactory factory)
factory
- public static void stopStart(StopWatch timeToStop, StopWatch timeToStart)
timeToStop
- - this one is stoppedtimeToStart
- - this one is startedpublic static void stripBaseName(java.lang.String baseName)
There can be multiple names stripped, with multiple calls to this method.
This is optional. A base name does not have to be specified.
baseName
-