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

Implement basic performance benchmark #80

Closed
TheButlah opened this issue Oct 12, 2020 · 2 comments · Fixed by #81
Closed

Implement basic performance benchmark #80

TheButlah opened this issue Oct 12, 2020 · 2 comments · Fixed by #81

Comments

@TheButlah
Copy link
Contributor

TheButlah commented Oct 12, 2020

Continuation of the discussion in #77.

We need to implement a basic performance benchmark, to detect any major performance regressions. docs.rs/criterion seems like a good choice. However, Its proving a lot more difficult than expected to use criterion to benchmark async code - its not clear to me exactly how to do this - I can't for example pass the &mut Criterion through to the async task, because its not Send

@TheButlah
Copy link
Contributor Author

TheButlah commented Oct 12, 2020

Yep, getting all manner of issues because criterion wants to pass a non-static ref along to a non-async function, so to invoke an async function I would need to to task::spawn() which needs a static ref. If anyone has any experience using criterion in async code, let me know

@TheButlah
Copy link
Contributor Author

TheButlah commented Oct 12, 2020

Update: I think I've figured out how to get this working. Here's what the code looks like right now. The key was manually creating the tokio runtime, and using block_on to block until the future completes. I think that this is the right way to do things:

fn criterion_benchmark(c: &mut Criterion) {
    let mut rt = Runtime::new().unwrap();
    let (mut pubs, mut subs) = rt.block_on(setup(4, 16));

    c.bench_function("m pubs and n subs messaging", |b| {
        b.iter(|| rt.block_on(f(&mut pubs, &mut subs)))
    });

    async fn f(pubs: &mut [PubSocket], subs: &mut [SubSocket]) {
        // Send/Recv messages
    }
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

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 a pull request may close this issue.

1 participant