Timer


Object Hierarchy:

GLib.Timer GLib.Timer GLib.Timer

Description:

[ Compact ]
[ CCode ( free_function = "g_timer_destroy" ) ]
public class Timer

`GTimer` records a start time, and counts microseconds elapsed since that time.

This is done somewhat differently on different platforms, and can be tricky to get exactly right, so `GTimer` provides a portable/convenient interface.

Example: Timers:

public static int main (string[] args) {
ulong microseconds;
double seconds;

// create a timer object:
Timer timer = new Timer ();

// 1. measurement, part 1:
for (int i = 0; i < 10000; i++);
timer.stop ();

seconds = timer.elapsed (out microseconds);
print ("1.1: %s, %lu\n", seconds.to_string (), microseconds);

// 1. measurement, part 2:
timer.@continue ();
for (int i = 0; i < 100000; i++);
timer.stop ();

seconds = timer.elapsed (out microseconds);
print ("1.2: %s, %lu\n", seconds.to_string (), microseconds);


// 2. measurement:
timer.reset ();
for (int i = 0; i < 10000; i++);
for (int i = 0; i < 100000; i++);
timer.stop ();

seconds = timer.elapsed (out microseconds);
print ("2.1: %s, %lu\n", seconds.to_string (), microseconds);
return 0;
}

valac --pkg glib-2.0 GLib.Timer.vala


Namespace: GLib
Package: glib-2.0

Content:

Creation methods:

Methods: