From 19cea83bd8520f6065e7e3af056de967af0edc9e Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Sun, 20 Nov 2022 17:05:11 +0100 Subject: [PATCH] use thread estimation if threads is set to 0 --- src/runner.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index a5ca36b..cabff5b 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -12,9 +12,16 @@ pub struct Runner { impl Runner { pub fn new(iterations: usize, threads: usize) -> Self { - Self { - iterations, - threads, + if threads == 0 { + match std::thread::available_parallelism() { + Ok(threads) => Runner { iterations, threads: threads.get() }, + Err(_) => Runner { iterations, threads: 1 }, + } + } else { + Runner { + iterations, + threads, + } } }