-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathclocks.c
More file actions
executable file
·71 lines (52 loc) · 1.83 KB
/
clocks.c
File metadata and controls
executable file
·71 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
** LuaProfiler
** Copyright Kepler Project 2005-2007 (http://www.keplerproject.org/luaprofiler)
** $Id: clocks.c,v 1.4 2007-08-22 19:23:53 carregal Exp $
*/
/*****************************************************************************
clocks.c:
Module to register the time (seconds) between two events
Design:
'lprofC_start_timer()' marks the first event
'lprofC_get_seconds()' gives you the seconds elapsed since the timer
was started
*****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include "clocks.h"
/*
Here you can choose what time function you are going to use.
These two defines ('TIMES' and 'CLOCK') correspond to the usage of
functions times() and clock() respectively.
Which one is better? It depends on your needs:
TIMES - returns the clock ticks since the system was up
(you may use it if you want to measure a system
delay for a task, like time spent to get input from keyboard)
CLOCK - returns the clock ticks dedicated to the program
(this should be prefered in a multithread system and is
the default choice)
note: I guess TIMES don't work for win32
*/
#ifdef TIMES
#include <sys/times.h>
static struct tms t;
#define times(t) times(t)
#else /* ifdef CLOCK */
#define times(t) clock()
#endif
void lprofC_start_timer(clock_t *time_marker) {
*time_marker = times(&t);
}
static clock_t get_clocks(clock_t time_marker) {
return times(&t) - time_marker;
}
float lprofC_get_seconds(clock_t time_marker) {
clock_t clocks;
clocks = get_clocks(time_marker);
return (float)clocks / (float)CLOCKS_PER_SEC;
}
#ifdef __cplusplus
}
#endif