Skip to content

factor: add benchmarks factoring many numbers in one invocation - #16439

Merged
sylvestre merged 2 commits into
uutils:mainfrom
DavidGailleton:factor-benches
Nov 15, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
DavidGailleton:factor-benches

Conversation

@DavidGailleton

Copy link
Copy Markdown
Contributor

Related to #1456.

The existing factor benchmarks call uumain once per number, so they mostly measure the startup. This adds four benchmarks that factor a few thousand numbers in one invocation: small numbers, the largest u64 values, the first values above 2^64 and products of two 31-bit primes.

Separate from the factorization change so the benchmarks exist on main first.

The existing benchmarks call uumain once per number, so they mostly measure
the startup. These run one invocation over a few thousand numbers: small
ones, the largest u64 values, the first values above 2^64 and products of
two 31-bit primes.
@codspeed

codspeed Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by ×3.2

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 2 improved benchmarks
✅ 16 untouched benchmarks
🆕 8 new benchmarks
⏩ 458 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory factor_small_factors_and_a_large_prime 104.8 KB 15.4 KB ×6.8
⚡ CPU Simulation factor_small_factors_and_a_large_prime 1,012.7 µs 682.1 µs +48.47%
🆕 CPU Simulation factor_batch_of_largest_u64s N/A 557.4 ms N/A
🆕 CPU Simulation factor_batch_of_semiprimes N/A 794.2 ms N/A
🆕 CPU Simulation factor_batch_of_small_numbers N/A 138.6 ms N/A
🆕 CPU Simulation factor_batch_of_smallest_u128s N/A 516.3 ms N/A
🆕 Memory factor_batch_of_largest_u64s N/A 796 KB N/A
🆕 Memory factor_batch_of_semiprimes N/A 199.5 KB N/A
🆕 Memory factor_batch_of_small_numbers N/A 7.5 MB N/A
🆕 Memory factor_batch_of_smallest_u128s N/A 885.4 KB N/A

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing DavidGailleton:factor-benches (42c0282) with main (b5223da)

Open in CodSpeed

Footnotes

  1. 458 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread src/uu/factor/benches/factor_bench.rs Outdated
.collect();
let products = primes
.iter()
.flat_map(|&p| primes.iter().map(move |&q| p * q))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gives pp squares and both pq and q*p, and with take(500) p only goes over the first 16 primes. could you please only take pairs with p < q?

The products contained squares and both p*q and q*p, and only the
first 16 primes were used as p.
/// above 2^31, where all the time goes into Pollard's rho.
#[divan::bench(sample_count = 10, sample_size = 1)]
fn factor_batch_of_semiprimes(bencher: Bencher) {
// The first primes above 2^31, 2^31 + 2^20, 2^31 + 2^21, ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the starts are 2^31 + i * 2^20, the "2^21, ..." reads like powers of two. maybe write it that way?

@sylvestre
sylvestre merged commit 1cbab48 into uutils:main Nov 15, 2026
104 of 106 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants