2
* timeu.c -- $Id: timeu.c 685 2003-03-08 15:26:51Z travo $
3
* p_cpu_secs for UNIX machines (ANSI C version not UNIX specific)
5
* Copyright (c) 1998. See accompanying LEGAL file for details.
11
/* if getrusage exists, it is likely best choice (eg- Digital UNIX) */
14
/* this is BSD way to get user and system time */
17
#include <sys/resource.h>
19
p_cpu_secs(double *sys)
22
getrusage(RUSAGE_SELF, &cpu);
23
if (sys) *sys = cpu.ru_stime.tv_sec + 1.0e-6*cpu.ru_stime.tv_usec;
24
return cpu.ru_utime.tv_sec + 1.0e-6*cpu.ru_utime.tv_usec;
30
/* this is POSIX 1003.1-1990 standard timing interface */
32
#define _POSIX_SOURCE 1
35
#include <sys/times.h>
36
/* try to handle modest deviations from POSIX standard (e.g.- Sun) */
40
# define CLK_TCK sysconf(_SC_CLK_TCK)
43
static double secs_per_tick = 0.0;
45
p_cpu_secs(double *sys)
49
if (secs_per_tick==0.0) secs_per_tick = 1./((double)CLK_TCK);
50
if (sys) *sys = cpu.tms_stime*secs_per_tick;
51
return cpu.tms_utime*secs_per_tick;
56
/* ANSI C standard should at least compile anywhere */
58
static double secs_per_tick = 0.0;
60
p_cpu_secs(double *sys)
62
if (secs_per_tick==0.0) secs_per_tick = 1./((double)CLOCKS_PER_SEC);
64
return clock()*secs_per_tick;