47#include <mach/clock.h> 
   53    void get_time(timespec* t) { 
 
   57      host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
 
   58      clock_get_time(cclock, &mts);
 
   59      mach_port_deallocate(mach_task_self(), cclock);
 
   60      t->tv_sec  = mts.tv_sec;
 
   61      t->tv_nsec = mts.tv_nsec;
 
   63      clock_gettime(CLOCK_MONOTONIC, t); 
 
   72      long long int sec,nsec;
 
   76      if ((now.tv_nsec-then.tv_nsec)<0) 
 
   78          sec = now.tv_sec-then.tv_sec-1;
 
   79          nsec = 1000000000L+now.tv_nsec-then.tv_nsec;
 
   83          sec = now.tv_sec-then.tv_sec;
 
   84          nsec = now.tv_nsec-then.tv_nsec;
 
   86      return sec + nsec*1e-9;
 
   89    void tick() { get_time(&then); }
 
   97#include <mach/mach_time.h> 
  101    mach_timebase_info_data_t base;
 
  102    void get_time(uint64_t* t) { *t=mach_absolute_time(); } 
 
  108        mach_timebase_info(&base);
 
  118        nsec = (now - then) * base.numer / base.denom;
 
  122    void tick() { get_time(&then); }