use std::{
thread,
time::{Duration, Instant},
};
use tango_bench::platform;
#[test]
fn check_rusage() {
#[cfg(not(target_os = "windows"))]
const TEST_DURATION: Duration = Duration::from_millis(100);
#[cfg(target_os = "windows")]
const TEST_DURATION: Duration = Duration::from_millis(1000);
let start_ts = Instant::now();
let rusage = {
let usage_before = platform::rusage();
while Instant::now() - start_ts < TEST_DURATION {
thread::spawn(|| {}).join().unwrap();
}
platform::rusage() - usage_before
};
assert!(rusage.system_time > rusage.user_time,
"Overhead of thread spawning (system time: {:?}) should be higher than cost of computations (user time: {:?})",
rusage.system_time, rusage.user_time);
}