Package ortus.boxlang.runtime.util
Class Timer
java.lang.Object
ortus.boxlang.runtime.util.Timer
This class is a utility for timing operations. You can use it as a static helper or as an instance.
It contains a map of timers that are started and stopped by label. The label is used to identify the timer.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear all timersstatic long
convert
(long time, Timer.TimeUnit timeUnit) This method receives a long time in nanoseconds and returns it in the appropriate time unitstatic Timer
create()
Create a new timer instance with auto remove timers set to truestatic Timer
create
(boolean autoRemoveTimers) Create a new timer instance with an auto remove timers optionGet all timersvoid
This convenience methods prints out to the console all the timers using the passed millisecondsvoid
printTimers
(Timer.TimeUnit timeUnit) This convenience methods prints out to the console all the timers using the passed timeunitStart a timer with the given labelStop the timer with the given label and return the elapsed time in the default of millisecondsstop
(String label, Timer.TimeUnit timeUnit) Stop the timer with the given label and return the elapsed time in the given time unitlong
stopAndGet
(String label, Timer.TimeUnit timeUnit) Returns a time in the specified time unitlong
stopAndGetMillis
(String label) Stop the timer with the given label and return the elapsed time in millisecondslong
stopAndGetNanos
(String label) Stop the timer with the given label and return the elapsed time in nanosecondslong
stopAndGetSeconds
(String label) Stop the timer with the given label and return the elapsed time in secondsstopAndPrint
(String label) Stop the timer with the given label, print the elapsed time in the default of millisecondsstopAndPrint
(String label, Timer.TimeUnit timeUnit) Stop the timer with the given label, print the elapsed time in the default of millisecondsstatic long
timeAndPrint
(Runnable runnable) Time the given runnable lambda, print the elapsed time in the default of milliseconds to the console, and return the elapsed time in the given time unit as longstatic long
timeAndPrint
(Runnable runnable, String label) Time the given runnable lambda, print the elapsed time in the default of milliseconds to the console, and return the elapsed time in the given time unit as longstatic long
timeAndPrint
(Runnable runnable, String label, Timer.TimeUnit timeUnit) Time the given runnable lambda, print the elapsed time in the given time unit to the console, and return the elapsed time in the given time unit as longTime the given runnable lambda and return the elapsed time in millisecondsTime the given runnable lambda and return the elapsed time in millisecondstimeIt
(Runnable runnable, Timer.TimeUnit timeUnit) Time the given runnable lambda and return the elapsed time in the given time unitlong
timeItRaw
(Runnable runnable, Timer.TimeUnit timeUnit) Time the given runnable lambda and return the elapsed time in the given time unit
-
Field Details
-
TIMING_FORMAT
The default timing format
-
-
Constructor Details
-
Timer
public Timer()Create a new timer instance with auto remove timers set to true -
Timer
public Timer(boolean autoRemoveTimers) Create a new timer instance- Parameters:
autoRemoveTimers
- Whether or not to auto remove timers when they are stopped
-
-
Method Details
-
create
Create a new timer instance with an auto remove timers option- Parameters:
autoRemoveTimers
- Whether or not to auto remove timers when they are stopped- Returns:
- The timer instance
-
create
Create a new timer instance with auto remove timers set to true- Returns:
- The timer instance
-
timeAndPrint
Time the given runnable lambda, print the elapsed time in the default of milliseconds to the console, and return the elapsed time in the given time unit as long- Parameters:
runnable
- The runnable lambda
-
timeAndPrint
Time the given runnable lambda, print the elapsed time in the default of milliseconds to the console, and return the elapsed time in the given time unit as long- Parameters:
runnable
- The runnable lambdalabel
- The label to use for the timer output
-
timeAndPrint
Time the given runnable lambda, print the elapsed time in the given time unit to the console, and return the elapsed time in the given time unit as long- Parameters:
runnable
- The runnable lambdalabel
- The label to use for the timer outputtimeUnit
- The time unit to return. Allowed values are SECONDS, MILLISECONDS, and NANOSECONDS
-
getTimers
Get all timers- Returns:
- The timers map
-
clearTimers
public void clearTimers()Clear all timers -
printTimers
This convenience methods prints out to the console all the timers using the passed timeunit -
printTimers
public void printTimers()This convenience methods prints out to the console all the timers using the passed milliseconds -
start
Start a timer with the given label- Parameters:
label
- The label- Returns:
- The timer instance
-
timeIt
Time the given runnable lambda and return the elapsed time in the given time unit- Parameters:
runnable
- The runnable lambdatimeUnit
- The time unit to return. Allowed values are SECONDS, MILLISECONDS, and NANOSECONDS- Returns:
- The elapsed time in the given time unit as a string
-
timeItRaw
Time the given runnable lambda and return the elapsed time in the given time unit- Parameters:
runnable
- The runnable lambdatimeUnit
- The time unit to return. Allowed values are SECONDS, MILLISECONDS, and NANOSECONDS- Returns:
- The elapsed time in the given time unit as a string
-
timeIt
Time the given runnable lambda and return the elapsed time in milliseconds- Parameters:
runnable
- The runnable lambda- Returns:
- The elapsed time in the given time unit as a string
-
timeIt
Time the given runnable lambda and return the elapsed time in milliseconds- Parameters:
runnable
- The runnable lambdalabel
- The label to use for the timer- Returns:
- The elapsed time in the given time unit as a string
-
stopAndGetSeconds
Stop the timer with the given label and return the elapsed time in seconds- Parameters:
label
- The label- Returns:
- The elapsed time in seconds
-
stopAndGetMillis
Stop the timer with the given label and return the elapsed time in milliseconds- Parameters:
label
- The label- Returns:
- The elapsed time in milliseconds
-
stopAndGetNanos
Stop the timer with the given label and return the elapsed time in nanoseconds- Parameters:
label
- The label- Returns:
- The elapsed time in nanoseconds
-
stopAndGet
Returns a time in the specified time unit- Parameters:
label
-timeUnit
-- Returns:
-
stop
Stop the timer with the given label and return the elapsed time in the given time unit- Parameters:
label
- The labeltimeUnit
- The time unit to return. Allowed values are SECONDS, MILLISECONDS, and NANOSECONDS- Returns:
- The elapsed time in the given time unit as a string: 123.45 seconds
-
stop
Stop the timer with the given label and return the elapsed time in the default of milliseconds- Parameters:
label
- The label- Returns:
- The elapsed time in milliseconds as a string: 123.45 milliseconds
-
stopAndPrint
Stop the timer with the given label, print the elapsed time in the default of milliseconds- Parameters:
label
- The label- Returns:
- The timer instance
-
stopAndPrint
Stop the timer with the given label, print the elapsed time in the default of milliseconds- Parameters:
label
- The label- Returns:
- The timer instance
-
convert
This method receives a long time in nanoseconds and returns it in the appropriate time unit- Parameters:
time
- The time in nanosecondstimeUnit
- The time unit to return. Allowed values are SECONDS, MILLISECONDS, and NANOSECONDS- Returns:
- The time in the given time unit
-