Description of the Timer class public functions
Timer class public functions
typedefs for int64bits:
- in UNIX with Gnu C: typedef long long int int64bits;
- in Microsoft Windows: typedef LONGLONG int64bits;
- Timer(void);
- Sets the ticks per second to 1000. Period is set to 1000.0
ticks. Takes 1/4 of a second to measure the CPU speed if very first
instantiation of class in program.
- Timer(int aSpeed);
- Sets the CPU speed to aSpeed. Sets
the ticks per second to 1000, and the period to 1000.0.
- Timer(Timer& aTimer);
- Copies the attributes of aTimer.
- ~Timer();
- Does nothing
- static int64bits clockCycles(void) const;
- Returns the present number of clock cycles since the last reboot.
Currently, this function only works on Pentium-class computers.
Return value is a 64-bit unsigned integer.
- double expired(void) const;
- Returns the number of periods which have expired (occured)
since the timer was last reset or updated.
- static int getCpuSpeed(void) const;
- Returns the CPU speed of the computer which was previously
set by the user or was measured automatically to an accuracy
of about 5%.
- double getPeriod(void) const;
- Returns the period length in terms of ticks per second.
The period is used to count larger units of tickes. The expired
function returns the number of periods which have occurred since
the last reset or an update.
- int getPeriodCount(void) const;
- Returns the period count in terms of the number of
periods since the starting position of the period pointer.
This function is similar to the expired function
which returns the number of periods which have occurred since the last
reset or an update as a floating-point fractional period count.
- int getTicksPerSecond(void) const;
- Returns the number of ticks per second for the timer. The default
is 1000 ticks per second, which is measurement in
terms of milliseconds.
- int getTime (void) const;
- Equivalent to calling getTimeInTicks.
- double getTimeInSeconds(void) const;
- Returns the time in seconds since the last reset or update.
The cpuSpeed must be correct for the time values to be accurate.
- int getTimeInTicks(void) const;
- Returns the time in ticks since the last reset. By default,
returns the time in milliseconds. See the setTicksPerSecond
function. Calls the clockCycles function for determining
time. For absolute time accuracy, the value of cpuSpeed needs be
properly set.
- int measureCpuSpeed(void) const;
- Returns the number of clock cycles in one second.
Accuracy is approximately +/- 5%.
- void reset(void);
- Resets the timer to 0 ticks.
- static void setCpuSpeed(int aSpeed);
- Sets the CPU speed used to calculate time in the getTimeTicks
and getTimeSeconds functions.
You can also vary the CPU speed to cause the getTime function to
output different units of time, but the setTicksPerSecond function
is a more appropriate place to do such a thing. Warning:
if you set the cpu speed of one Timer object, it will affect
all other Timer objects.
- void setPeriod(double aPeriod);
- Sets the period which is used for counting in the expired() function.
- void setTempo(double beatsPerMinute);
- Sets the period which is used for counting in the expired() function.
Tempo is specified in beats per minute.
- void setTicksPerSecond(int aTickRate);
- Sets the number of ticks produced per second. If reset
function is not called, then there will be a discontinuity in
getTime values before and after the call to the
setTicksPerSecond function because time in seconds since
a reset will be used to calculate the number of ticks.
If the default of 1000 ticks per second is used, the timer must
be reset after 24.9 days of continuous running (assuming 200 MHz
CPU clock rate). If ticks per second were 1,000,000, i.e.,
one microsecond resolution, then the
maximum time before reset would be shortened to 36 minutes for a
200 MHz CPU.
- void start(start);
- Does the same thing as the reset function.
- void sync(Timer& aTimer);
- Synchronizes time zero in the timer with the specified input aTimer.
The ticksPerSecond are left unchanged in both timers and
must be equivalent to give identical timings with getTime
function.
- void sync(int64bits aCycleCount);
- Synchronizes time zero within the timer with the specified
clock cycle count.
- void update(void);
- Increments the timer offset by one period.
- void update(int periodCount);
- Increments the timer offset by peroidCount periods.
Send comments/errors on this page to
craig@ccrma.stanford.edu