We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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()
Future
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:
@arnauorriols the result of setup() is passed directly to routine, which simplifies the type signature:
setup()
routine
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 setup to be async would require yet another iter_batched_async_setup method:
setup
iter_batched_async_setup
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 setup, do what you need and return the value directly.
Sorry, something went wrong.
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, ) });
Successfully merging a pull request may close this issue.
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: