From 1ddbee7f37c6d2e9f8eae5742e948909a3569bd6 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 20 Sep 2017 13:19:00 -0700 Subject: [PATCH] bigint mac3: tweak thresholds between algorithms It's not too rigorous, but thresholds 32 and 256 give me better results. Before: test multiply_0 ... bench: 87 ns/iter (+/- 0) test multiply_1 ... bench: 11,926 ns/iter (+/- 19) test multiply_2 ... bench: 772,178 ns/iter (+/- 3,068) test multiply_3 ... bench: 2,034,237 ns/iter (+/- 9,618) After: test multiply_0 ... bench: 87 ns/iter (+/- 0) test multiply_1 ... bench: 11,927 ns/iter (+/- 64) test multiply_2 ... bench: 672,440 ns/iter (+/- 3,570) test multiply_3 ... bench: 1,577,065 ns/iter (+/- 11,137) --- bigint/src/algorithms.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigint/src/algorithms.rs b/bigint/src/algorithms.rs index 8a133b2..d93bdd5 100644 --- a/bigint/src/algorithms.rs +++ b/bigint/src/algorithms.rs @@ -260,12 +260,12 @@ fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) { // The thresholds are somewhat arbitrary, chosen by evaluating the results // of `cargo bench --bench bigint multiply`. - if x.len() <= 16 { + if x.len() <= 32 { // Long multiplication: for (i, xi) in x.iter().enumerate() { mac_digit(&mut acc[i..], y, *xi); } - } else if x.len() <= 300 { + } else if x.len() <= 256 { /* * Karatsuba multiplication: *