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

warmup #17

Open
FilipAndersson245 opened this issue Oct 30, 2023 · 4 comments
Open

warmup #17

FilipAndersson245 opened this issue Oct 30, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@FilipAndersson245
Copy link

Hello, it would be nice if it would be possible to add warmup runs, in my benchmark case the first run is always slower as some data has to be fetched into memory, and it always drags down the "real" lowest benchmark lowest as this is done only once.
I would suggest #[divan::bench(warmup=10) or something simular with the default being either zero or a 1.

@nvzqz
Copy link
Owner

nvzqz commented Oct 30, 2023

Are you suggesting in this case that Divan would discard the first 10 samples after it finds a proper sample size?

Perhaps we could have something like:

#[divan::bench(
    // Discard at least the first 10 samples.
    warmup_sample_count = 10,
    // Discard samples until 1 second has elapsed.
    // This would use `IntoDuration` like `min_time`.
    warmup_min_time = 1,
)

In the meantime, I recommend moving out the benchmark closure and doing your own custom warmup.

#[divan::bench]
fn my_bench(bencher: divan::Bencher) {
    let work_fn = || {
        // Benchmarked work in here.
    };

    // Warmup:
    for _ in 0..1000 {
        work_fn();
    }

    // Benchmark:
    bencher.bench(work_fn);
}

@nvzqz nvzqz added the enhancement New feature or request label Oct 30, 2023
@FilipAndersson245
Copy link
Author

Are you suggesting in this case that Divan would discard the first 10 samples after it finds a proper sample size?

Perhaps we could have something like:

#[divan::bench(
    // Discard at least the first 10 samples.
    warmup_sample_count = 10,
    // Discard samples until 1 second has elapsed.
    // This would use `IntoDuration` like `min_time`.
    warmup_min_time = 1,
)

Yee something like that would be very nice.

In the meantime, I recommend moving out the benchmark closure and doing your own custom warmup.

#[divan::bench]
fn my_bench(bencher: divan::Bencher) {
    let work_fn = || {
        // Benchmarked work in here.
    };

    // Warmup:
    for _ in 0..1000 {
        work_fn();
    }

    // Benchmark:
    bencher.bench(work_fn);
}

that would work for me, Thanks 👍

@dvdplm
Copy link

dvdplm commented Sep 30, 2024

It'd probably be a good default to have a warmup. One thing users coming to divan from criterion will notice is that the output is noisier with divan.

@nanoqsh
Copy link

nanoqsh commented Dec 15, 2024

+1

I noticed a performance degradation in a test after renaming (so the test ended up at the top of the list). This is very confusing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants