Package trclib.timer
Class TrcHighPrecisionTime
java.lang.Object
trclib.timer.TrcHighPrecisionTime
This class provides high precision time with nanosecond precision but not necessarily nanosecond resolution
(that is, how frequently the value changes). There is no guarantee except that the resolution is at least as
good as that of System.currentTimeMillis().
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrcHighPrecisionTime
(String instanceName) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Returns the current time in seconds.double
This method returns the elapsed time in seconds since the last recorded timestamp.double
getElapsedTime
(double epochTime) This method returns the elapsed time in seconds of the specified epoch time from the recorded epoch timestamp.void
This method is called to take a snapshot of the current nano time as the start timestamp and the corresponding current time in milliseconds.toString()
This method returns the performance data in string form.
-
Field Details
-
instanceName
-
timestampNano
private volatile long timestampNano -
timestampEpoch
private volatile double timestampEpoch
-
-
Constructor Details
-
TrcHighPrecisionTime
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name of the time object.
-
-
Method Details
-
toString
This method returns the performance data in string form. -
recordTimestamp
public void recordTimestamp()This method is called to take a snapshot of the current nano time as the start timestamp and the corresponding current time in milliseconds. -
getElapsedTime
public double getElapsedTime()This method returns the elapsed time in seconds since the last recorded timestamp.- Returns:
- elapsed time from last recorded timestamp in seconds.
-
getElapsedTime
public double getElapsedTime(double epochTime) This method returns the elapsed time in seconds of the specified epoch time from the recorded epoch timestamp.- Parameters:
epochTime
- specifies the epoch time to compute the elapsed time from the recorded epoch timestamp.- Returns:
- elapsed time in seconds from the recorded epoch timestamp.
-
getCurrentTime
public double getCurrentTime()Returns the current time in seconds. Note that while the unit of time of the return value is in seconds, the precision is in nanoseconds but not necessarily nanosecond resolution (that is, how frequently the value changes). There is no guarantee except that the resolution is at least as good as that of System.currentTimeMillis().- Returns:
- the time difference in seconds, between the current time and midnight, January 1, 1970 UTC with nanosecond precision.
-