Skip to content
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

revert #7 #11

Closed
wants to merge 1 commit into from
Closed

revert #7 #11

wants to merge 1 commit into from

Conversation

yoshuawuyts
Copy link
Collaborator

Reverts #7 as per #9. Thanks!

Signed-off-by: Yoshua Wuyts <[email protected]>
/// b.iter(|| {
/// println!("hello world");
/// })
/// println!("hello world");
Copy link

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
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
Copy link

ghost commented Nov 3, 2019

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
Copy link

ghost commented Nov 3, 2019

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