3 ** Copyright Kepler Project 2005-2007 (http://www.keplerproject.org/luaprofiler)
4 ** $Id: clocks.c,v 1.4 2007/08/22 19:23:53 carregal Exp $
7 /*****************************************************************************
9 Module to register the time (seconds) between two events
12 'lprofC_start_timer()' marks the first event
13 'lprofC_get_seconds()' gives you the seconds elapsed since the timer
15 *****************************************************************************/
21 Here you can choose what time function you are going to use.
22 These two defines ('TIMES' and 'CLOCK') correspond to the usage of
23 functions times() and clock() respectively.
24 Which one is better? It depends on your needs:
25 TIMES - returns the clock ticks since the system was up
26 (you may use it if you want to measure a system
27 delay for a task, like time spent to get input from keyboard)
28 CLOCK - returns the clock ticks dedicated to the program
29 (this should be prefered in a multithread system and is
32 note: I guess TIMES don't work for win32
37 #include <sys/times.h>
41 #define times(t) times(t)
43 #else /* ifdef CLOCK */
45 #define times(t) clock()
50 void lprofC_start_timer(clock_t *time_marker
) {
51 *time_marker
= times(&t
);
54 static clock_t get_clocks(clock_t time_marker
) {
55 return times(&t
) - time_marker
;
58 float lprofC_get_seconds(clock_t time_marker
) {
60 clocks
= get_clocks(time_marker
);
61 return (float)clocks
/ (float)CLOCKS_PER_SEC
;