scc

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

clock.c (350B)


      1 #include "clock.h"
      2 
      3 extern int _getrusage(int, struct rusage*);
      4 
      5 static clock_t
      6 convtick(struct rusage r)
      7 {
      8 	return r.ru_utime.tv_sec*CLOCKS_PER_SEC +
      9 	       r.ru_stime.tv_usec / (1000000 / CLOCKS_PER_SEC);
     10 }
     11 
     12 
     13 clock_t
     14 clock(void)
     15 {
     16 	struct rusage ru;
     17 	clock_t c;
     18 
     19 	if (_getrusage(RUSAGE_SELF, &ru))
     20 		return ((clock_t) -1);
     21 	return convtick(ru);
     22 }