async-std icon indicating copy to clipboard operation
async-std copied to clipboard

couldn't find bench macro in async_std

Open GopherJ opened this issue 4 years ago • 8 comments

It seems I cannot have async_std::bench attribute even when I activate attributes feature

GopherJ avatar Apr 13 '20 08:04 GopherJ

Anyone knows how to avoid using block_on in rust bench:

b.iter(|| // how to execute async function here using async_std)

seems like block_on is a little bit heavy and I would like to avoid using block_on in bench iter

GopherJ avatar Apr 13 '20 09:04 GopherJ

@GopherJ you can use https://docs.rs/futures/0.3.4/futures/executor/index.html and task::spawn https://docs.rs/async-std/1.5.0/async_std/task/index.html#spawning-a-task

humb1t avatar Apr 16 '20 17:04 humb1t

@humb1t I think it's not a good idea to create an async runtime in bench iterator, because in that case the creating time will be counted in.

GopherJ avatar Apr 16 '20 20:04 GopherJ

you can create ThreadPool before b.iter() and use one runtime for entire benchmark like you do to preconfigure another environment entities.

humb1t avatar Apr 17 '20 12:04 humb1t

@humb1t could you give an example? because for me I don't think it'll work because I still cannot use async code in b.iter

GopherJ avatar Apr 17 '20 16:04 GopherJ

It seems I cannot have async_std::bench attribute even when I activate attributes feature

See also https://github.com/async-rs/async-attributes/issues/9 and https://github.com/async-rs/async-std/issues/70#issuecomment-528042987

taiki-e avatar May 03 '20 17:05 taiki-e

@GopherJ sorry - didn't check notifications for a while.

https://github.com/hyperledger/iroha/blob/iroha2-dev/iroha_client/benches/torii.rs this is our current benches, but we block inside iter.

humb1t avatar Jun 04 '20 07:06 humb1t

@humb1t hi no pb. I think block_on inside iter will give incorrect figures. especially for [email protected] and tokio

GopherJ avatar Jun 04 '20 09:06 GopherJ