Interface Time
- All Known Implementing Classes:
MicroSeconds, MilliSeconds, NanoSeconds
Interface Time.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMICROS_PER_MS = 1000.static final intMICROS_PER_SEC = MICROS_PER_MS * MS_PER_SEC.static final intMS_PER_MIN = MS_PER_SEC * SECONDS_PER_MIN.static final intMS_PER_SEC = 1000.static final intNS_PER_MICRO = 1000.static final intNS_PER_MS = NS_PER_MICRO * MICROS_PER_MS.static final longNS_PER_SEC = MS_PER_SEC * NS_PER_MS.static final intNumber of seconds per minute. -
Method Summary
Modifier and TypeMethodDescriptiondoubleconvertToMicroSeconds(double t) convert the time to Micro seconds.doubleconvertToMilliSeconds(double t) convert the time to Milliseconds.doubleconvertToNanoSeconds(double t) convert the time to Nanoseconds.default longelapsed(long h, long l) get the duration between two time stamps.doubleelapsedMilliSeconds(long h, long l) get the elapsed Time in milliseconds.doubleelapsedSeconds(long h, long l) get the elapsed Time in seconds.longget the current Time.get the Time Unit.default longsecondsToTimeUnits(long seconds) Convert a duration in seconds to this clock's native unit.
-
Field Details
-
SECONDS_PER_MIN
static final int SECONDS_PER_MINNumber of seconds per minute.- See Also:
-
NS_PER_MICRO
static final int NS_PER_MICRONS_PER_MICRO = 1000.- See Also:
-
MICROS_PER_MS
static final int MICROS_PER_MSMICROS_PER_MS = 1000.- See Also:
-
MS_PER_SEC
static final int MS_PER_SECMS_PER_SEC = 1000.- See Also:
-
NS_PER_MS
static final int NS_PER_MSNS_PER_MS = NS_PER_MICRO * MICROS_PER_MS.- See Also:
-
NS_PER_SEC
static final long NS_PER_SECNS_PER_SEC = MS_PER_SEC * NS_PER_MS.- See Also:
-
MS_PER_MIN
static final int MS_PER_MINMS_PER_MIN = MS_PER_SEC * SECONDS_PER_MIN.- See Also:
-
MICROS_PER_SEC
static final int MICROS_PER_SECMICROS_PER_SEC = MICROS_PER_MS * MS_PER_SEC.- See Also:
-
-
Method Details
-
getTimeUnit
-
getCurrentTime
long getCurrentTime()get the current Time.- Returns:
- current Time
-
elapsed
default long elapsed(long h, long l) get the duration between two time stamps.- Parameters:
h- time stampl- time stamp, the l should be less than h- Returns:
- elapsed time.
-
secondsToTimeUnits
default long secondsToTimeUnits(long seconds) Convert a duration in seconds to this clock's native unit.The conversion is intended for benchmark-loop setup so duration checks can use integer subtraction without a per-operation floating point conversion.
- Parameters:
seconds- duration in seconds- Returns:
- duration expressed in this clock's native unit
- Throws:
ArithmeticException- if the converted duration overflows a long
-
elapsedMilliSeconds
double elapsedMilliSeconds(long h, long l) get the elapsed Time in milliseconds.- Parameters:
h- time stampl- time stamp, the l should be less than h- Returns:
- elapsed time in milliseconds
-
elapsedSeconds
double elapsedSeconds(long h, long l) get the elapsed Time in seconds.- Parameters:
h- time stampl- time stamp, the l should be less than h- Returns:
- elapsed time in seconds
-
convertToNanoSeconds
double convertToNanoSeconds(double t) convert the time to Nanoseconds.- Parameters:
t- time duration- Returns:
- converted time in nanoseconds
-
convertToMicroSeconds
double convertToMicroSeconds(double t) convert the time to Micro seconds.- Parameters:
t- time duration- Returns:
- converted time in microseconds
-
convertToMilliSeconds
double convertToMilliSeconds(double t) convert the time to Milliseconds.- Parameters:
t- time duration- Returns:
- converted time in Milliseconds
-