diff --git a/Modules/timemodule.c b/Modules/timemodule.c --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -40,6 +40,10 @@ #include #endif +#if defined(__APPLE__) +#include +#endif + /* Forward declarations */ static int floatsleep(double); static double floattime(void); @@ -816,7 +820,8 @@ calls is valid."); #if (defined(MS_WINDOWS) && !defined(__BORLANDC__)) \ - || (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) + || (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) \ + || (defined(__APPLE__)) # define HAVE_PYTIME_MONOTONIC #endif @@ -826,6 +831,16 @@ { #if defined(MS_WINDOWS) && !defined(__BORLANDC__) return win32_clock(0); +#elif defined(__APPLE__) + uint64_t time = mach_absolute_time(); + uint64_t nsec; + + static mach_timebase_info_data_t timebase; + if (timebase.denom == 0) + mach_timebase_info(&timebase); + + nsec = time * timebase.numer / timebase.denom; + return PyFloat_FromDouble(nsec * 1e-9); #else static int clk_index = 0; clockid_t clk_ids[] = {