1Adapted from https://github.com/zcash/libsnark/pull/10
2
3diff --git a/depends/libff/libff/common/profiling.cpp b/depends/libff/libff/common/profiling.cpp
4index f2a1985..319149c 100755
5--- a/depends/libff/libff/common/profiling.cpp
6+++ b/depends/libff/libff/common/profiling.cpp
7@@ -27,6 +27,13 @@
8 #include <proc/readproc.h>
9 #endif
10
11+#ifdef __MACH__
12+#include <time.h>
13+#include <sys/time.h>
14+#include <mach/clock.h>
15+#include <mach/mach.h>
16+#endif
17+
18 namespace libff {
19
20 long long get_nsec_time()
21@@ -42,10 +49,20 @@ long long get_nsec_cpu_time()
22 return 0;
23 #else
24 ::timespec ts;
25+#ifdef __MACH__
26+ clock_serv_t cclock;
27+ mach_timespec_t mts;
28+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
29+ clock_get_time(cclock, &mts);
30+ mach_port_deallocate(mach_task_self(), cclock);
31+ ts.tv_sec = mts.tv_sec;
32+ ts.tv_nsec = mts.tv_nsec;
33+#else
34 if ( ::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) )
35 throw ::std::runtime_error("clock_gettime(CLOCK_PROCESS_CPUTIME_ID) failed");
36 // If we expected this to work, don't silently ignore failures, because that would hide the problem and incur an unnecessarily system-call overhead. So if we ever observe this exception, we should probably add a suitable #ifdef .
37 //TODO: clock_gettime(CLOCK_PROCESS_CPUTIME_ID) is not supported by native Windows. What about Cygwin? Should we #ifdef on CLOCK_PROCESS_CPUTIME_ID or on __linux__?
38+#endif
39 return ts.tv_sec * 1000000000ll + ts.tv_nsec;
40 #endif
41 }