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

how to call async functions during setup process? #748

Open
pdeva opened this issue Dec 11, 2023 · 1 comment
Open

how to call async functions during setup process? #748

pdeva opened this issue Dec 11, 2023 · 1 comment

Comments

@pdeva
Copy link

pdeva commented Dec 11, 2023

i have code like that needs to read from S3, like this:

fn bench_s3(c: &mut Criterion) {
  let rt = tokio::runtime::Runtime::new().unwrap();
  let mut get_group = c.benchmark_group("s3_get");
    for (_, file) in files.iter().enumerate() {
        get_group.bench_with_input(
            BenchmarkId::new("single_file", file),
            file,
            |bencher, mybody| {
                bencher
                    .to_async(&rt)
                    .iter(|| async { s3_get_single(file).await });
            },
        );
    }
}

however, there needs to be a separate 'setup' part which actually PUTs those files to s3. and that portion will also be async. However, the bench_s3 method itself cannot be async. So where am I supposed to call the async setup method to setup my benchmarks?

@shepmaster
Copy link

You can use AsyncBencher::method.iter_custom. Something like:

.iter_custom(|| async { 
    s3_put().await;

    let start = Instant::now();
    s3_get_single(file).await;
    start.elapsed()
 });

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

No branches or pull requests

2 participants