-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AsyncBencher::iter_batched()
setup closure to return a Future
#576
Comments
@arnauorriols the result of pub fn iter_batched<I, O, S, R, F>(&mut self, mut setup: S, mut routine: R, size: BatchSize)
where
S: FnMut() -> I,
R: FnMut(I) -> F,
F: Future<Output = O>, I'm guessing to allow pub fn iter_batched_async_setup<I, O, S, R, F>(&mut self, mut setup: S, mut routine: R, size: BatchSize)
where
S: FnMut() -> Future<Output = I>,
R: FnMut(I) -> F,
F: Future<Output = O>, Probably easier to spin up your own runtime in |
Its a bit tricky to spawn the runtime since you can't make a new one (in Tokio at least), but this seems to work: c.bench_function("async setup", |b| {
b.to_async(Runtime::new().unwrap()).iter_batched(
|| {
let (mut tx, rx) = std::sync::mpsc::channel();
let s = Handle::current().spawn(async move {
let s = TcpStream::connect(addr).await.unwrap();
tx.send(s).unwrap();
});
rx.recv().unwrap()
},
|r| {
async move {
println!("call {a}: {}", r.local_addr().unwrap());
}
},
BatchSize::PerIteration,
)
}); |
Just like the Routine, the Setup is also likely to be async, when benching async code. Is there any particular reason why the setup is not async?
The text was updated successfully, but these errors were encountered: