• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!-- ##### SECTION Title ##### -->
2Timers
3
4<!-- ##### SECTION Short_Description ##### -->
5keep track of elapsed time
6
7<!-- ##### SECTION Long_Description ##### -->
8<para>
9#GTimer records a start time, and counts microseconds elapsed since that time.
10This is done somewhat differently on different platforms, and can be tricky to
11get exactly right, so #GTimer provides a portable/convenient interface.
12</para>
13<note><para>
14#GTimer uses a higher-quality clock when thread support is available.
15Therefore, calling g_thread_init() while timers are running may lead to
16unreliable results. It is best to call g_thread_init() before starting
17any timers, if you are using threads at all.
18</para></note>
19
20<!-- ##### SECTION See_Also ##### -->
21<para>
22
23</para>
24
25<!-- ##### SECTION Stability_Level ##### -->
26
27
28<!-- ##### STRUCT GTimer ##### -->
29<para>
30Opaque datatype that records a start time.
31</para>
32
33
34<!-- ##### FUNCTION g_timer_new ##### -->
35<para>
36Creates a new timer, and starts timing (i.e. g_timer_start() is implicitly
37called for you).
38</para>
39
40@Returns: a new #GTimer.
41
42
43<!-- ##### FUNCTION g_timer_start ##### -->
44<para>
45Marks a start time, so that future calls to g_timer_elapsed() will report the
46time since g_timer_start() was called. g_timer_new() automatically marks the
47start time, so no need to call g_timer_start() immediately after creating the
48timer.
49</para>
50
51@timer: a #GTimer.
52
53
54<!-- ##### FUNCTION g_timer_stop ##### -->
55<para>
56Marks an end time, so calls to g_timer_elapsed() will return the difference
57between this end time and the start time.
58</para>
59
60@timer: a #GTimer.
61
62
63<!-- ##### FUNCTION g_timer_continue ##### -->
64<para>
65Resumes a timer that has previously been stopped with g_timer_stop().
66g_timer_stop() must be called before using this function.
67</para>
68
69@timer: a #GTimer.
70@Since: 2.4
71
72
73<!-- ##### FUNCTION g_timer_elapsed ##### -->
74<para>
75If @timer has been started but not stopped, obtains the time since the timer was
76started. If @timer has been stopped, obtains the elapsed time between the time
77it was started and the time it was stopped. The return value is the number of
78seconds elapsed, including any fractional part. The @microseconds
79out parameter is essentially useless.
80<warning><para>Calling initialization functions, in particular g_thread_init(),
81while a timer is running will cause invalid return values from this function.
82</para></warning>
83</para>
84
85@timer: a #GTimer.
86@microseconds: return location for the fractional part of seconds elapsed,
87  in microseconds (that is, the total number of microseconds elapsed, modulo
88   1000000), or %NULL
89@Returns: seconds elapsed as a floating point value, including
90  any fractional part.
91
92
93<!-- ##### FUNCTION g_timer_reset ##### -->
94<para>
95This function is useless; it's fine to call g_timer_start() on an
96already-started timer to reset the start time, so g_timer_reset() serves no
97purpose.
98</para>
99
100@timer: a #GTimer.
101
102
103<!-- ##### FUNCTION g_timer_destroy ##### -->
104<para>
105Destroys a timer, freeing associated resources.
106</para>
107
108@timer: a #GTimer to destroy.
109
110
111