class SF::Clock

Overview

Utility class that measures the elapsed time

SF::Clock is a lightweight class for measuring time.

Its provides the most precise time that the underlying OS can achieve (generally microseconds or nanoseconds). It also ensures monotonicity, which means that the returned time can never go backward, even if the system time is changed.

Usage example:

clock = SF::Clock.new
# [...]
time1 = clock.elapsed_time
# [...]
time2 = clock.restart

The SF::Time value returned by the clock can then be converted to a number of seconds, milliseconds or even microseconds.

See also: SF::Time

Defined in:

system/obj.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Default constructor

The clock starts automatically after being constructed.


[View source]

Instance Method Detail

def dup : Clock #
Description copied from class Reference

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.


[View source]
def elapsed_time : Time #

Get the elapsed time

This function returns the time elapsed since the last call to #restart() (or the construction of the instance if #restart() has not been called).

Returns: Time elapsed


[View source]
def finalize #

[View source]
def restart : Time #

Restart the clock

This function puts the time counter back to zero. It also returns the time elapsed since the clock was started.

Returns: Time elapsed


[View source]