scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

clock.c (722B)


      1 #include <time.h>
      2 
      3 #include <sys.h>
      4 
      5 #include "time.h"
      6 
      7 #define TOCLOCK(r) (r.tv_sec * CLOCKS_PER_SEC +\
      8                     r.tv_usec / (1000000 / CLOCKS_PER_SEC))
      9 
     10 struct rusage {
     11 	struct timeval ru_utime;
     12 	struct timeval ru_stime;
     13 	long int ru_maxrss;
     14 	long int ru_ixrss;
     15 	long int ru_idrss;
     16 	long int ru_isrss;
     17 	long int ru_minflt;
     18 	long int ru_majflt;
     19 	long int ru_nswap;
     20 	long int ru_inblock;
     21 	long int ru_oublock;
     22 	long int ru_msgsnd;
     23 	long int ru_msgrcv;
     24 	long int ru_nsignals;
     25 	long int ru_nvcsw;
     26 	long int ru_nivcsw;
     27 };
     28 
     29 extern int _getrusage(int, struct rusage*);
     30 
     31 clock_t
     32 clock(void)
     33 {
     34 	struct rusage ru;
     35 
     36 	if (_getrusage(RUSAGE_SELF, &ru))
     37 		return -1;
     38 
     39 	return TOCLOCK(ru.ru_utime) + TOCLOCK(ru.ru_stime);
     40 }