class Espresso::Timer

Overview

High-resolution time input.

Defined in:

espresso/timer.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(running = false) #

Creates and optionally starts a new timer.


[View source]

Class Method Detail

def self.frequency #

Frequency, in Hz, of the raw timer.

See also: Timer#value.


[View source]
def self.global #

Retrieves the value (in seconds) of the GLFW timer. Unless the timer has been set using #global=, the timer measures time elapsed since GLFW was initialized.

The resolution of the timer is system dependent, but is usually on the order of a few micro- or nanoseconds. It uses the highest-resolution monotonic time source on each supported platform.


[View source]
def self.global=(time) #

Sets the value (in seconds) of the GLFW timer. It then continues to count up from that value. The value must be a positive finite number less than or equal to 18,446,744,073.0, which is approximately 584.5 years.

The upper limit of the timer is calculated as: floor((2^64 - 1) / 10^9) and is due to implementations storing nanoseconds in 64 bits. The limit may be increased in the future.


[View source]
def self.measure(&) #

Measures how long a block takes to execute and returns a time span.


[View source]
def self.value #

Current value of the raw timer, measured in 1 / frequency seconds. To get the frequency, call #frequency.


[View source]

Instance Method Detail

def microseconds #

Total elapsed time in microseconds (10^-6). Might be rounded depending on the system's precision.


[View source]
def milliseconds #

Total elapsed time in milliseconds (10^-3). Might be rounded depending on the system's precision.


[View source]
def nanoseconds #

Total elapsed time in nanoseconds (10^-9). Might be rounded depending on the system's precision.


[View source]
def reset #

Resets the timer back to zero. The timer will continue running if it already was.


[View source]
def running? : Bool #

Indicates whether the timer is currently running.


[View source]
def seconds #

Total elapsed time in seconds.


[View source]
def span #

Creates a Time::Span from the timer's value.


[View source]
def start #

Starts (or restarts) the timer. If multiple consecutive calls are made to this method, then it has the effect of restarting the the current time segment at the last call. Any previous time accumulated before this call is kept. Call #reset to completely restart the timer to zero.


[View source]
def stop #

Stops the timer.


[View source]
def value #

Raw value of the current timer.


[View source]