-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
48 lines (41 loc) · 894 Bytes
/
timer.c
File metadata and controls
48 lines (41 loc) · 894 Bytes
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
static char rcsid[] = "$Id: timer.c,v 1.1.1.1 2004-02-06 18:14:56 msato Exp $";
/*
* $RWC_Release$
* $RWC_Copyright$
*/
/* timer functions */
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
/* #define USE_GETRUSAGE */
double second()
{
double t;
#ifdef USE_GETRUSAGE
struct rusage ru;
getrusage(RUSAGE_SELF, &ru);
t = (double)(ru.ru_utime.tv_sec+ru.ru_stime.tv_sec) +
((double)(ru.ru_utime.tv_usec+ru.ru_stime.tv_usec))/1.0e6 ;
return t ;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
t = (double)(tv.tv_sec) + ((double)(tv.tv_usec))/1.0e6;
return t ;
#endif
}
static double start_time;
double start_timer()
{
start_time = second();
return start_time;
}
double lap_time(char *msg)
{
double t;
t = second();
if (msg)
printf("%s %f\n", msg, t-start_time);
return t;
}