Crates.io | os_clock |
lib.rs | os_clock |
version | 0.3.1 |
source | src |
created_at | 2020-09-10 20:47:18.144288 |
updated_at | 2020-09-11 03:01:35.165306 |
description | Operating system clocks, for measuring with cpu time |
homepage | https://github.com/benaubin/os_clocks |
repository | https://github.com/benaubin/os_clocks |
max_upload_size | |
id | 287154 |
size | 17,819 |
Access various operating system clocks (such as per-thread CPU Time, system clock, monotomic, etc) on Unix-family systems.
use os_clock::{self, Clock};
let clock = cpu_clock_for_current_thread();
clock.get_time();
Notably, a clock for the CPU time of one thread can be accessed from another thread:
let clock = cpu_clock_for_current_thread().unwrap();
loop {
if clock.get_time().unwrap() > Duration::from_millis(5) {
break;
}
}
std::thread::spawn(move || {
assert!(clock.get_time().unwrap() > Duration::from_millis(5));
let self_clock = cpu_clock_for_current_thread().unwrap();
assert!(self_clock.get_time().unwrap() < Duration::from_millis(1));
})
.join()
.unwrap();
Works on recent iOS, Mac, as well as Unix-family systems with a pthread.h
that defines pthread_getcpuclockid
(most modern Linux).