Skip to content

Commit 482277b

Browse files
committed
Fix bench_iterations clamp to allow a minimum of 1
1 parent 6c07bb1 commit 482277b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/template/runner.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ fn run_timed<I: Clone, T>(func: impl Fn(I) -> T, input: I, hook: impl Fn(&T)) ->
5050
fn bench<I: Clone, T>(func: impl Fn(I) -> T, input: I, base_time: &Duration) -> (Duration, u128) {
5151
let mut stdout = stdout();
5252

53-
print!(" > {ANSI_ITALIC}benching{ANSI_RESET}");
54-
let _ = stdout.flush();
55-
56-
let bench_iterations = (Duration::from_secs(1).as_nanos() / cmp::max(base_time.as_nanos(), 10)).clamp(10, 10000);
53+
let bench_iterations = (Duration::from_secs(1).as_nanos() / cmp::max(base_time.as_nanos(), 10)).clamp(1, 10000);
5754

5855
let mut timers: Vec<Duration> = vec![];
5956

57+
if bench_iterations == 1 {
58+
return (base_time.clone(), 1);
59+
}
60+
6061
for _ in 0..bench_iterations {
6162
// need a clone here to make the borrow checker happy.
6263
let cloned = input.clone();

0 commit comments

Comments
 (0)