Compare commits

4 Commits
Author SHA1 Message Date
nortega 98cb2f58ea Implement average of multiple trials. 2025-12-05 16:19:44 +01:00
nortega 073276da10 Add benchmarking script. 2025-12-05 15:50:38 +01:00
nortega 56a094730c Remove unnecessary cast. 2025-12-05 15:50:25 +01:00
nortega 3a4a5c8849 Change help information for num option. 2025-12-05 15:47:31 +01:00
2 changed files with 24 additions and 2 deletions
Executable
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
BIN="./target/release/indivisible"
TRIALS=20
if ! [ -f "$BIN" ]
then
>&2 echo "Release build not available. Please run 'cargo build -r'."
exit 1
fi
echo "Calculating primes up to 100,000,000"
TOTAL="0"
for _ in $(seq "$TRIALS")
do
TIME=$(command time -f "%e" "$BIN" 100000000 2>&1 >/dev/null)
TOTAL=$(calc "$TOTAL + $TIME")
done
AVG=$(calc "$TOTAL / $TRIALS")
echo "Average time: ${AVG}s"
+2 -2
View File
@@ -31,7 +31,7 @@ struct Opt {
import:Option<PathBuf>,
#[structopt(short, long, help = "Test if num is prime instead of generation")]
test:bool,
#[structopt(help = "Ordinal of the prime to generate or number to test for primality")]
#[structopt(help = "Max of the prime to generate or number to test for primality")]
num:u64,
#[structopt(short, long, name = "n", default_value = "1", help = "Number of threads to spawn")]
jobs:u64,
@@ -92,7 +92,7 @@ fn main() {
}
for i in 5..=(f64::sqrt(opts.num as f64) as u64 + 1) as usize {
if !arr[i as usize] {
if !arr[i] {
continue;
}