Timer functions Timer functions Introduction Timer functions This section describes the timer functions that are provided by GLIB. g_timer_new GTimer *g_timer_new void (null) Description Allocate a new timer and return the pointer to the newly allocated timer structure. If enough resources are not available for a new timer structure NULL will be returned. This function will also start the timer once it has been allocated. Usage GTimer *timer; timer = g_timer_new (); Parameters void (null) This function takes no arguments g_timer_destroy void g_timer_destroy GTimer *timer Description This will destroy and free up the resources used by the timer previously created with g_timer_new(). You should call this function when your done with the timer in question. Usage GTimer *timer; timer = g_timer_new (); /* do something useful with the timer */ g_timer_destroy (timer); Parameters GTimer *timer The pointer to the GTimer structre you wish to destroy. g_timer_start void g_timer_start GTimer *timer Description This will re-start the previously allocated timer running. Usage GTimer *timer; timer = g_timer_new (); g_timer_stop (timer); /* do stuff we don't want to time */ g_timer_start (timer); /* do the stuff we want timed */ Parameters GTimer *timer The timer to start that has been previously allocted with g_timer_new (); g_timer_stop void g_timer_stop GTimer *timer Description This will stop a running timer. Usage GTimer *timer; /* allocate and start new timer */ timer = g_timer_new (); /* do anything you want timed with this timer */ g_timer_stop (timer); /* And stop the timer at the end */ Parameters GTimer *timer A pointer to the previously allocated timer structre to stop. g_timer_reset void g_timer_reset GTimer *timer Description Reset a previously allocated timer to prepare to time another sequence of events. Usage GTimer *timer; /* allocate a timer */ timer = g_timer_new (); /* timed function loop or what have you */ g_timer_stop (timer); g_timer_reset (timer); g_timer_start (timer); /* loop here with a clean timer */ g_timer_destroy (timer); /* done with the timer */ Parameters GTimer *timer A pointer to a previously allocated timer structure. g_timer_elapsed gdouble g_timer_elapsed GTimer *timer gulong *microseconds Description Get the elapsed time between all g_timer_start() and the g_timer_stop() function calls. The return value of this function is in seconds and the microseconds argument will contain the microseconds value. If you are not intrested in the microseconds value just pass a NULL as the second parameter. Usage GTimer *timer gdouble seconds; gulong microseconds; timer = g_timer_new (); /* do something that you want timed. */ g_timer_stop (timer); seconds = g_timer_elapsed (timer, \µseconds); g_print ("Elapsed time was %f seconds and %f microseconds\n", seconds, microseconds); g_timer_destroy (timer);