| Crates.io | future-timed |
| lib.rs | future-timed |
| version | 0.1.0 |
| created_at | 2025-08-24 21:05:27.053324+00 |
| updated_at | 2025-08-24 21:05:27.053324+00 |
| description | Future timing Instrumentation. Instrumentation to record the busy and idle time taken by a future as it is driven to completion. |
| homepage | |
| repository | https://github.com/matze/future-timed |
| max_upload_size | |
| id | 1808775 |
| size | 28,070 |
Future timing instrumentation for Rust async code.
future-timed provides instrumentation to record the time taken by a future. It
tracks the busy time which is the sum of all time consumed during calls to
Future::poll on the future and the idle time which is The sum of all time
between calls to Future::poll (excluding time before first poll)
Add future-timed to your Cargo.toml:
future-timed = "0.1"
Use the TimedFutureExt extension trait to add timing instrumentation to any future:
use future_timed::{TimedFutureExt, Timing};
async fn main() {
let output = some_async_fn()
.timed(|Timing { idle, busy }| {
println!("Future was idle for {:?} and busy for {:?}", idle, busy);
})
.await;
// Use the output as normal
}
You can also use the standalone timed function:
use future_timed::{timed, Timing};
async fn main() {
let output = timed(some_async_fn(), |Timing { idle, busy }| {
println!("Future was idle for {:?} and busy for {:?}", idle, busy);
}).await;
}
Unlike similar crates, future-timed allows you to report timing data inline
and compose with subsequent future combinators:
use future_timed::{TimedFutureExt, Timing};
use futures::future::FutureExt;
async fn main() {
let output = async {
// Some async operation
21
}
.timed(|Timing { busy, .. }| {
println!("busy for {busy:?}");
})
.map(|n| 2 * n)
.await;
assert_eq!(output, 42);
}
Note that in this case, timing data is for all wrapped futures.
This project is licensed under the MIT license.
Based on the future-timing crate but with a different API.