forked from iveney/cs2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
21 lines (17 loc) · 787 Bytes
/
timer.c
File metadata and controls
21 lines (17 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
/*********************************************************************/
/* */
/* current processor time in seconds */
/* difference between two calls is processor time spent by your code */
/* needs: <sys/types.h>, <sys/times.h> */
/* depends on compiler and OS */
/* */
/*********************************************************************/
static double timer ()
{
struct rusage r;
getrusage(0, &r);
return (double)(r.ru_utime.tv_sec+r.ru_utime.tv_usec/(double)1000000);
}