diff options
author | Aria Shrimpton <me@aria.rip> | 2024-03-01 15:01:53 +0000 |
---|---|---|
committer | Aria Shrimpton <me@aria.rip> | 2024-03-01 15:01:53 +0000 |
commit | e2b39431ffaaac9378cdd95de43688160044366a (patch) | |
tree | 94d7d9eb73a2ab668130d92813a3dd58f45c5116 | |
parent | 258f9112871570bd9d65359bd814d033374d302e (diff) |
benchmark for fixed amount rather than time-based
otherwise, we'll skew the fit of our curves to lower n values
-rw-r--r-- | src/crates/benchmarker/src/lib.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/crates/benchmarker/src/lib.rs b/src/crates/benchmarker/src/lib.rs index 7f1a0f8..1a7d519 100644 --- a/src/crates/benchmarker/src/lib.rs +++ b/src/crates/benchmarker/src/lib.rs @@ -31,7 +31,9 @@ fn print_result(op: &str, n: usize, measurement: BenchmarkResult) { ) } -/// Benchmark an operation for approx 5 seconds, returning the results. +const TO_RUN: usize = 50; + +/// Benchmark an operation [`TO_RUN`] times, returning the results. /// /// `setup` is used to create the thing `op` acts on, and `undo` is called between each run to undo `op`. /// If `undo` is invalid, this will return garbage results. @@ -51,11 +53,14 @@ fn benchmark_op<T, R>( warmup_n += 1; } - let to_run = (warmup_n * (MEASUREMENT_TIME.as_millis() / WARM_UP_TIME.as_millis())) as usize; - let mut times = Vec::with_capacity(to_run); + println!( + "benchmarking for estimated {}ms", + (WARM_UP_TIME / warmup_n * TO_RUN as u32).as_millis() + ); + let mut times = Vec::with_capacity(TO_RUN); // Benchmarking loop - for _ in 0..to_run { + for _ in 0..TO_RUN { let mut target = black_box(setup()); let start = Instant::now(); |