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() { }
How many ticks (from the ticks
function) are in a second.
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.
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 |
dstTicksPerSecond |
The ticks per second to convert |
Return
The converted value.
Initialises the ticksPerSecond
value.