note
QM
Here's a benchmark for [cpan://Math::Big::Factors] wheels of orders 5-7:
<code>
Rate 7 6 5
7 34.1/s -- -95% -100%
6 627/s 1739% -- -94%
5 9770/s 28548% 1458% --
</code>
and for <code>factors_wheel</code> of numbers near 32 bits, using an order 7 wheel:
<code>
s/iter 4294967291 4294967293 4294967295
4294967291 4.45 -- -61% -71%
4294967293 1.74 156% -- -25%
4294967295 1.31 241% 33% --
</code>
Note that 4294967291 is prime, 4294967293 has 2 large factors, and 4294967295 has 5 factors, the largest of which is 2**16+1.
<p>
For 4294967291, and wheel orders 5-7:
<code>
s/iter 7 5 6
7 4.44 -- -16% -21%
5 3.71 19% -- -6%
6 3.49 27% 6% --
</code>
In all fairness, I should probably mention that I've customized my own version of [Math::Big::Factors] to [cpan://Memoize] results where possible, and to reduce the calls to <code>Math::BigInt::new()</code> for constants.
<p>
Note that <code>factors_wheel</code> creates a new wheel every time (what a shame), instead of requiring a wheel reference be passed in. Caching <code>wheel</code> goes a little way in correcting this, without changing the interface.
<p>
You might also consider avoiding the use of [cpan://Math::BigInt] where possible, as you don't need numbers that big.
<p>
Now, back to the question at hand. For numbers near 2**32, factoring a prime number seems to take 150 times longer than creating the order 7 wheel. Creating the order 6 wheel is considerably faster, and so is the factoring based on that wheel.
<p>
I'm not sure where the breakpoint is for order 7 wheels. A casual search hints that it is very large.
<div class="pmsig"><div class="pmsig-294463">
<p>-QM<br />
--<br />
Quantum Mechanics: The dreams stuff is made of
</div></div>
481987
482714