beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luaprofiler / clocks.c
blobe693c48535fd61930ebf4e60bf6f6b3c246bc937
1 /*
2 ** LuaProfiler
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 $
5 */
7 /*****************************************************************************
8 clocks.c:
9 Module to register the time (seconds) between two events
11 Design:
12 'lprofC_start_timer()' marks the first event
13 'lprofC_get_seconds()' gives you the seconds elapsed since the timer
14 was started
15 *****************************************************************************/
17 #include <stdio.h>
18 #include "clocks.h"
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
30 the default choice)
32 note: I guess TIMES don't work for win32
35 #ifdef TIMES
37 #include <sys/times.h>
39 static struct tms t;
41 #define times(t) times(t)
43 #else /* ifdef CLOCK */
45 #define times(t) clock()
47 #endif
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) {
59 clock_t clocks;
60 clocks = get_clocks(time_marker);
61 return (float)clocks / (float)CLOCKS_PER_SEC;