+in "C" `{
+
+#ifdef __APPLE__
+ #include <TargetConditionals.h>
+ #if defined(TARGET_OS_IPHONE) && __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
+ // Preserve compatibility with pre-iOS 10 devices where there is no clock_get_time.
+ #undef CLOCK_REALTIME
+ #endif
+#endif
+
+#if (defined(__MACH__) || defined(TARGET_OS_IPHONE)) && !defined(CLOCK_REALTIME)
+/* OS X does not have clock_gettime, mascarade it and use clock_get_time
+ * cf http://stackoverflow.com/questions/11680461/monotonic-clock-on-osx
+*/
+#include <mach/clock.h>
+#include <mach/mach.h>
+#undef CLOCK_REALTIME
+#undef CLOCK_MONOTONIC
+#define CLOCK_REALTIME CALENDAR_CLOCK
+#define CLOCK_MONOTONIC SYSTEM_CLOCK
+void nit_clock_gettime(clock_t clock_name, struct timespec *ts) {
+ clock_serv_t cclock;
+ mach_timespec_t mts;
+ host_get_clock_service(mach_host_self(), clock_name, &cclock);
+ clock_get_time(cclock, &mts);
+ mach_port_deallocate(mach_task_self(), cclock);
+ ts->tv_sec = mts.tv_sec;
+ ts->tv_nsec = mts.tv_nsec;
+}
+#else
+ #define nit_clock_gettime clock_gettime
+#endif
+`}
+
+# Elapsed time representation.
+private extern class Timespec `{struct timespec*`}
+
+ # Init a new Timespec from `s` seconds and `ns` nanoseconds.