]> git.lizzy.rs Git - rust.git/commit
Optimize and fix time::precise_time_ns() on macos
authorKevin Ballard <kevin@sb.org>
Thu, 15 May 2014 00:54:36 +0000 (17:54 -0700)
committerKevin Ballard <kevin@sb.org>
Fri, 16 May 2014 21:02:14 +0000 (14:02 -0700)
commit8ef3e227198f6ff674b1626d0862c4112358c1a1
tree52938169b18421a54344649686e5b33a7f4e320e
parent25c54226c3e7dd6f59cf2e92238a4d79d8b0128d
Optimize and fix time::precise_time_ns() on macos

Use sync::one::Once to fetch the mach_timebase_info only once when
running precise_time_ns(). This helps because mach_timebase_info() is
surprisingly inefficient. Also fix the order of operations when applying
the timebase to the mach absolute time value.

This improves the time on my machine from

```
test tests::bench_precise_time_ns ... bench:       157 ns/iter (+/- 4)
```

to

```
test tests::bench_precise_time_ns ... bench:        38 ns/iter (+/- 3)
```

and it will get even faster once #14174 lands.
mk/crates.mk
src/libtime/lib.rs