Skip to content

Commit

Permalink
Added benchmark for mod_multi() and then improved speed by 8%
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmayhew committed Feb 21, 2024
1 parent 2904168 commit 3170abd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pages/primalitytest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ fn modmult(mut a: u64, mut b: u64, n: u64) -> u64 {
if (b & 1) == 1 {
t = modadd(t, f, n);
}
//TODO: bitshift might be cleaner and faster
b = (b as f64 / 2.0).floor() as u64;
b >>= 1;
f = modadd(f, f, n);
}
t = modadd(t, f, n);
Expand Down Expand Up @@ -373,4 +372,10 @@ mod tests {
assert_eq!(modmult(3, 3, 4), 1);
assert_eq!(modmult(110, 4, 7), 6);
}

#[bench]
fn mod_mult_bench(b: &mut Bencher) {
b.iter(|| modmult(3, 3, 4));
b.iter(|| modmult(110, 4, 7));
}
}

0 comments on commit 3170abd

Please sign in to comment.