Skip to content

revert #7#11

Closed
yoshuawuyts wants to merge 1 commit into
masterfrom
revert-7
Closed

revert #7#11
yoshuawuyts wants to merge 1 commit into
masterfrom
revert-7

Conversation

@yoshuawuyts

Copy link
Copy Markdown
Collaborator

Reverts #7 as per #9. Thanks!

Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Comment thread src/lib.rs
/// b.iter(|| {
/// println!("hello world");
/// })
/// println!("hello world");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we missing b.iter(...) here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now part of the macro again, unfortunately.

@ghost

ghost commented Nov 3, 2019

Copy link
Copy Markdown

I did some more thinking on #[bench].

test::Bencher was not designed to work with async code because it uses this b.iter(|| {}) method that measures the time elapsed inside the closure.

So we're forced to do something like:

b.iter(|| task::block_on(async {}));

This is silly if our microbenchmark is defined as:

#[async_attributes::bench]
async fn foo(b: &mut Bencher) {
    b.iter(|| task::block_on(async {}));
}

Which means we have an async fn, but then also this blocking closure, so we have to call block_on. So we go from async world into sync world and then back into async world. :)

I think a more ideal interface for Bencher would be:

b.iter_async(async {}).await;

Unfortunately, Bencher was not designed for async code. Perhaps we should not take it as an argument in our #[bench] async fn?

I'm going back and forth on how we should hack around these limitations. There is no good solution, but perhaps this would be the best one right now:

#[bench]
#(#attrs)*
fn #name(b: &mut test::Bencher) {
    let _ = b.iter(|| async_std::task::block_on(async { #body }));
}

@ghost

ghost commented Nov 3, 2019

Copy link
Copy Markdown

Also, let's add a simple benchmark just for CI/testing purposes :)

use std::time::Duration;
use async_std::task;

#[async_attributes::bench]
async fn sleep() {
    task::sleep(Duration::from_micros(100)).await;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant