Optimized Ord::cmp function#155
Open
mikem8891 wants to merge 2 commits into
Open
Conversation
Member
|
I have in mind a way to make the current code iterative without changing the overall approach as much. I would at least like to compare that to yours, so if you could share your benchmark, that would be great. |
Author
|
https://github.com/mikem8891/num-bench
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implementation of the
Ord::cmpfunction does several early comparisons to try to determine ordering before resulting to div and mod operations. This allows about half of unsignedRatio<T>pairs and 3/4 of signedRatio<T>pairs to be determined using simple comparisons (based on the entire input space, individual results may vary). If simple comparisons don't determine the ordering, then the function enters a tight loop to converge on a solution as quickly as possible.Note, #121 would be faster, but would still benefit from this pull request if
checked_mulreturnsNone.I confirmed this fixes #140 . This solution is iterative instead of recursive.
This should also fixes #146 . I phoned this in because I think negative denominators should not be adversely affecting performance or complexity compared to normal fractions.
For context, here are some benchmark results
I can make this benchmark available to you if needed.
This is a repost of #147 because I accidentally closed it after the crate was refactored into modules.