module watt.io.monotonic

Get precise timing information from the OS.

Precise timing information (exactlty how precise varies based on hardware and operating system) is useful for a number of things; Games, simulations, profiling, etc.

Code Map

//! Get precise timing information from the OS.
module watt.io.monotonic;


//! Get the ticks from the OS in an i64.
alias ticks = vrt_monotonic_ticks;

//! How many ticks (from the ticks function) are in a second.
global ticksPerSecond: i64;

//! Convert a time from one frequency to another.
fn convClockFreq(ticks: i64, srcTicksPerSecond: i64, dstTicksPerSecond: i64) i64 { }
//! Initialises the ticksPerSecond value.
fn __ctor() { }
global ticksPerSecond: i64

How many ticks (from the ticks function) are in a second.

alias ticks

Get the ticks from the OS in an i64.

One tick value is not useful in isolation, but take a second and you can tell how many ticks elapsed via simple subtraction.

Example

a := ticks();
aFunctionThatTakesALongTime();
delta := ticks() - a;

How many ticks in a second, and the resolution varies from system to system. Use ticksPerSecond and convClockFreq to turn this into an understandable value.

fn convClockFreq(ticks: i64, srcTicksPerSecond: i64, dstTicksPerSecond: i64) i64

Convert a time from one frequency to another.

Example

origin := ticks();
while (true) {
    now := ticks();
    delta := now - origin;
    ms := convClockFreq(delta, ticksPerSecond, 1000);
    writefln("%s milliseconds have passed.", ms);
}

Parameters

ticks

The ticks value to convert.

srcTicksPerSecond

The ticks per second of the ticks parameter.

dstTicksPerSecond

The ticks per second to convert ticks to.

Return

The converted value.

fn __ctor()

Initialises the ticksPerSecond value.