Repository: time-rs/time (language: rust)

Issue:
precise_time_ns is ~1.5-2x slower on OSX than hand-written code
If I implement it simply myself it's 1.5-2x faster.  Tracked it down & it looks like it's due to the compiler not being able to inline stuff.


Discussion / hints:

Fix patch:
diff --git a/benches/precise_time_ns.rs b/benches/precise_time_ns.rs
index d9170ea26..2f92226f8 100644
--- a/benches/precise_time_ns.rs
+++ b/benches/precise_time_ns.rs
@@ -7,5 +7,8 @@ use test::Bencher;
 
 #[bench]
 fn bench_precise_time_ns(b: &mut Bencher) {
-    b.iter(|| time::precise_time_ns())
+    b.iter(|| {
+        time::precise_time_ns();
+        time::precise_time_ns();
+    });
 }
diff --git a/src/lib.rs b/src/lib.rs
index 0407d3322..02ac7775d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -156,6 +156,7 @@ pub fn get_time() -> Timespec {
  * Returns the current value of a high-resolution performance counter
  * in nanoseconds since an unspecified epoch.
  */
+#[inline]
 pub fn precise_time_ns() -> u64 {
     sys::get_precise_ns()
 }
diff --git a/src/sys.rs b/src/sys.rs
index 3a7d4348a..1471dd63f 100644
--- a/src/sys.rs
+++ b/src/sys.rs
@@ -348,6 +348,7 @@ mod inner {
             (tv.tv_sec as i64, tv.tv_usec * 1000)
         }
 
+        #[inline]
         pub fn get_precise_ns() -> u64 {
             unsafe {
                 let time = libc::mach_absolute_time();


Test patch: