mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
factor::table: Optimise the size of the precomputed table
A too-large precomputed table actually slows down the program: we spend time fetching it from disk and from memory (into the CPU's cache), and larger prime factors are more unlikely to occur in random integers (prime p occurs with probability ~1/p when sampling 64b numbers uniformly-at-random) The new value was chosen after measuring the execution time (for all integers between 2 and 10⁷) for a broad set of values: | n | time (s) | |------|----------| | 16 | 40.84 | | 32 | 34.491 | | 64 | 29.044 | | 128 | 25.121 | | 192 | 23.98 | | 256 | 23.102 | | 256 | 24.93 | | 272 | 23.57 | | 288 | 23.85 | | 304 | 23.91 | | 320 | 23.24 | | 329 | 23.45 | | 336 | 23.55 | | 352 | 23.09 | | 368 | 23.65 | | 384 | 23.32 | | 384 | 23.36 | | 400 | 23.30 | | 416 | 23.38 | | 432 | 23.42 | | 448 | 23.95 | | 448 | 24.00 | | 464 | 23.81 | | 480 | 23.55 | | 496 | 24.10 | | 512 | 24.101 | | 512 | 24.23 | | 1027 | 29.864 |
This commit is contained in:
parent
9d992b77b2
commit
8e040bbf1a
1 changed files with 1 additions and 1 deletions
|
@ -39,7 +39,7 @@ fn main() {
|
|||
let mut file = File::create(&Path::new(&out_dir).join("prime_table.rs")).unwrap();
|
||||
|
||||
// By default, we print the multiplicative inverses mod 2^64 of the first 1k primes
|
||||
const DEFAULT_SIZE: usize = 1027;
|
||||
const DEFAULT_SIZE: usize = 320;
|
||||
let n = args()
|
||||
.nth(1)
|
||||
.and_then(|s| s.parse::<usize>().ok())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue