137124Sbostic /* 2*61111Sbostic * Copyright (c) 1989, 1993 3*61111Sbostic * The Regents of the University of California. All rights reserved. 437124Sbostic * 542620Sbostic * %sccs.include.redist.c% 637124Sbostic */ 737124Sbostic 837124Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*61111Sbostic static char sccsid[] = "@(#)clock.c 8.1 (Berkeley) 06/04/93"; 1037124Sbostic #endif /* LIBC_SCCS and not lint */ 1137124Sbostic 1245143Sbostic #include <sys/param.h> 1337124Sbostic #include <sys/time.h> 1437124Sbostic #include <sys/resource.h> 1537124Sbostic 1645143Sbostic /* 1745143Sbostic * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, 1845143Sbostic * but this would overflow if we switch to nanosec. 1945143Sbostic */ 2045143Sbostic #define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) 2145143Sbostic 2237124Sbostic clock_t clock()2337124Sbosticclock() 2437124Sbostic { 2545143Sbostic struct rusage ru; 2637124Sbostic 2745143Sbostic if (getrusage(RUSAGE_SELF, &ru)) 2842195Skarels return ((clock_t) -1); 2945143Sbostic return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime)))); 3037124Sbostic } 31