The fastest low-level method is to read system runtime from the processor using mach_absolute_time ()
#include <mach/mach_time.h> int systemUptime() { static float timebase_ratio; if (timebase_ratio == 0) { mach_timebase_info_data_t s_timebase_info; (void) mach_timebase_info(&s_timebase_info); timebase_ratio = (float)s_timebase_info.numer / s_timebase_info.denom; } return (int)(timebase_ratio * mach_absolute_time() / 1000000000); }
Note that timebase_ratio is different for processors. For example, on a macbook it is 1, whereas on an iPhone 5 it is 125/3 (~ 40).
malex source share