Class AbstractChrono
- java.lang.Object
-
- umontreal.iro.lecuyer.util.AbstractChrono
-
- Direct Known Subclasses:
- Chrono, ChronoSingleThread, GlobalCPUTimeChrono, SystemTimeChrono, ThreadCPUTimeChrono
public abstract class AbstractChrono extends java.lang.ObjectAbstractChrono is a class that acts as an interface to the system clock and calculates the CPU or system time consumed by parts of a program.Every object of class AbstractChrono acts as an independent stopwatch. Several AbstractChrono objects can run at any given time. The method
initresets the stopwatch to zero,getSeconds,getMinutesandgetHoursreturn its current reading, andformatconverts this reading to aString. The returned value includes the execution time of the method from AbstractChrono.Below is an example of how it may be used. A stopwatch named timer is constructed (and initialized). When 2.1 seconds of CPU time have been consumed, the stopwatch is read and reset to zero. Then, after an additional 330 seconds (or 5.5 minutes) of CPU time, the stopwatch is read again and the value is printed to the output in minutes.
AbstractChrono timer = new Chrono();
suppose 2.1 CPU seconds are used here
double t = timer.getSeconds(); // Here, t = 2.1
timer.init();
t = timer.getSeconds(); // Here, t = 0.0
suppose 330 CPU seconds are used here.
t = timer.getMinutes(); // Here, t = 5.5
System.out.println (timer.format()); // Prints: 0:5:30.00
-
-
Constructor Summary
Constructors Constructor and Description AbstractChrono()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.Stringformat()Converts the CPU time used by the program since its last call toinitfor this AbstractChrono to aStringin the HH:MM:SS.xx format.static java.lang.Stringformat(double time)Converts the time time, given in seconds, to aStringin the HH:MM:SS.xx format.doublegetHours()Returns the CPU time in hours used by the program since the last call toinitfor this AbstractChrono.doublegetMinutes()Returns the CPU time in minutes used by the program since the last call toinitfor this AbstractChrono.doublegetSeconds()Returns the CPU time in seconds used by the program since the last call toinitfor this AbstractChrono.voidinit()Initializes this AbstractChrono to zero.
-
-
-
Method Detail
-
init
public void init()
Initializes this AbstractChrono to zero.
-
getSeconds
public double getSeconds()
Returns the CPU time in seconds used by the program since the last call toinitfor this AbstractChrono.- Returns:
- the number of seconds
-
getMinutes
public double getMinutes()
Returns the CPU time in minutes used by the program since the last call toinitfor this AbstractChrono.- Returns:
- the number of minutes
-
getHours
public double getHours()
Returns the CPU time in hours used by the program since the last call toinitfor this AbstractChrono.- Returns:
- the number of hours
-
format
public java.lang.String format()
Converts the CPU time used by the program since its last call toinitfor this AbstractChrono to aStringin the HH:MM:SS.xx format.- Returns:
- the string representation of the CPU time
-
format
public static java.lang.String format(double time)
Converts the time time, given in seconds, to aStringin the HH:MM:SS.xx format.- Returns:
- the string representation of the time time
-
-
DMelt 3.0 © DataMelt by jWork.ORG