use std::future::Future;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
pub fn time_on_runtime<Fut>(make_future: impl FnOnce() -> Fut + Send + 'static) -> Duration
where
Fut: Future<Output = ()> + 'static,
{
std::thread::spawn(move || {
let slot: Arc<Mutex<Duration>> = Arc::new(Mutex::new(Duration::ZERO));
let writer = Arc::clone(&slot);
runite::spawn(async move {
let start = Instant::now();
make_future().await;
*writer.lock().expect("timing slot poisoned") = start.elapsed();
});
runite::run();
*slot.lock().expect("timing slot poisoned")
})
.join()
.expect("runtime benchmark thread panicked")
}