Skip to content

Number of iterations does not scale #133

Closed
@mbillingr

Description

@mbillingr

I tried to get started with Criterion by basically copy&pasting the Getting Started guide into a new cargo project. Then, running cargo bench never finished collecting samples.

By reducing the fibonacci number and the measurement time I finally managed to get results.

This is the result for fibonacci(5):

     Running target/release/deps/my_benchmark-78226dbc85d4a50d
Benchmarking fib 20
Benchmarking fib 20: Warming up for 3.0000 s
Benchmarking fib 20: Collecting 100 samples in estimated 1.0000 s (3776268800 iterations)
Benchmarking fib 20: Analyzing
fib 20                  time:   [264.64 ps 265.14 ps 265.68 ps]
                        change: [-0.3371% +0.1094% +0.5162%] (p = 0.63 > 0.05)
                        No change in performance detected.
Found 10 outliers among 100 measurements (10.00%)
  5 (5.00%) high mild
  5 (5.00%) high severe
slope  [264.64 ps 265.68 ps] R^2            [0.9907413 0.9906445]
mean   [264.90 ps 266.51 ps] std. dev.      [2.1733 ps 5.7740 ps]
median [263.74 ps 264.71 ps] med. abs. dev. [0.3246 ps 1.6775 ps]

cargo bench --bench my_benchmark -- --verbose  18.72s user 0.30s system 189% cpu 10.044 total

And for This is the result for fibonacci(10):

     Running target/release/deps/my_benchmark-78226dbc85d4a50d
Benchmarking fib 20
Benchmarking fib 20: Warming up for 3.0000 s
Benchmarking fib 20: Collecting 100 samples in estimated 1.0000 s (3777415150 iterations)
Benchmarking fib 20: Analyzing
fib 20                  time:   [169.19 ns 169.66 ns 170.14 ns]
                        change: [+63543.59036036591% +63803.46521022125% +64058.9672116039%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 20 outliers among 100 measurements (20.00%)
  4 (4.00%) high mild
  16 (16.00%) high severe
slope  [169.19 ns 170.14 ns] R^2            [0.9864471 0.9864016]
mean   [169.33 ns 170.21 ns] std. dev.      [1.6465 ns 2.7644 ns]
median [168.69 ns 168.72 ns] med. abs. dev. [50.328 ps 177.27 ps]

cargo bench --bench my_benchmark -- --verbose  656.87s user 0.32s system 101% cpu 10:49.57 total

The total cargo run times (12.72s and 656.87s) include compilation and analysis time, but these should be mostly negligible compared to the time spent collecting samples, especially in the second case.

Interestingly, the number of iterations is almost the same in both runs (3776M and 3777M). Since the function is supposed to run slower in the second run, I assume there should be less iterations. Could there be a problem with estimating the required number of iterations from the warm-up phase?


Update

I was able to reproduce the behavior on my laptop. Both system run stable-x86_64-unknown-linux-gnu toolchain with rustc 1.24.1. Here is the code I used: https://github.com/mbillingr/criterion-test.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions