-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
factor: use num_prime crate's u64 and u128 factorization methods to speed up the performance of calculating prime numbers for u64 and u128 #9171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
GNU testsuite comparison: |
|
A few comments :
|
|
Noted! I removed the GNU link in my PR and I'll keep that in mind about showing results with hyperfine in the future. In the meantime, I will start making benchmarking tests (and fix that cspell check it seems to be complaining about on Ubuntu). |
CodSpeed Performance ReportMerging #9171 will improve performances by 3.5%Comparing Summary
Benchmarks breakdown
Footnotes
|
|
GNU testsuite comparison: |
|
From the big_uint benchmarking, I noticed there were some issues with retrieving the prime factors of certain numbers like This issue is mentioned in #1559, but with the current implementation uutils' factor should support up to |
|
GNU testsuite comparison: |
|
Could you please move the benchmarks into a separate pr so that we have a baseline? Thanks |
0e02bf2 to
d10f756
Compare
|
GNU testsuite comparison: |
9d782de to
28fafb9
Compare
120fc9f to
1838797
Compare
…peed up the performance of calculating prime numbers for u64 and u128
1838797 to
7622e9f
Compare
|
GNU testsuite comparison: |
not a huge win but still an improvement, thanks! |
Currently, in
factor.rs, it opts to usenum_primecrate'sfactors()method only.num_primealso has specific prime factorization methods foru64andu128targets (factorize64()andfactorize128()), which seems to be suited and faster for those situations (which improves partially upon the performance issue mentioned in #1456). This PR uses those specific methods in the event that we're given an integer that fits as a u64 or u128.In terms of performance, running
seq 2 10000000 | factorusingnum_prime'sfactors()vsnum_prime'sfactorizeu64()shows the following results from hyperfine:With
factors()With
factorize64()Any feedback and suggestions on making the changes in this PR compact would be nice as well. I haven't found a way to neatly convert
BigUinttou64oru128from reading through thenum_bigintcrate docs, and due to usingu64/u128/BigUinttypes for theBTreeMap, I have three different write_result methods to handle each case.Pertaining to comparing this with GNU's factor, I'm skeptical about the timing results mentioned on hyperfine. Without any visible outputs, hyperfine indicates that GNU's factor runs the following command in 1.2 seconds:
However, I read through this closed issue mentioned in hyperfine's repo: sharkdp/hyperfine#377 and it seems like there are situations where GNU's commands changes its execution if it detects that stdout is
/dev/null(which Hyperfine attachesStdio::null()to stdout of the command). I'm not certain if this is the case for how GNU's factor work, but when I run GNU's factor with--show-output flag, it gives me the following timing result (which seems to be more accurate on how long GNU's factor takes):Comparing GNU's factor to the changes made by this PR with --show-output flag on in hyperfine shows the following:
GNU's factor is definitely still faster than uutils' factor. In the future, it might be better to experiment with other prime factorization crates or make our own efficient implementation of prime factorization in Rust for performance gain.