-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-4356: Add key parameter to functions in bisect module #11781
bpo-4356: Add key parameter to functions in bisect module #11781
Conversation
Hi Raymond, thanks for your comment. I may be missing something but I'm not convinced the key function will get called multiple time per value. I did some research before implementing this and I think your first point comes from the implementation of the In binary search, most elements are not touched and it element About your second point, I think you say this because of the branching in the hot path. I did some tests before posting the pull request. The performance seems to be the same (I'm not sure this is a good to measure it thought, I would love some input on that):
I guess the branch predictor does a good job here (?) and why no change of performance is seen (does someone know a good reference on branch predictors, out-of-order execution and other low-level performance details? I would like to learn more about them). If I'm not making any mistake, the Am I missing the point completely? |
Here's an example where
It seems not to be an issue:
|
I found this whilst composing a message to Python-ideas about adding a I had also considered asking for a custom "comparator" argument, but quickly realised |
CC @rhettinger |
Misc/NEWS.d/next/Library/2019-02-07-15-44-12.bpo-4356.i6h86W.rst
Outdated
Show resolved
Hide resolved
Thanks for the feedback @dimaqq! |
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key argument should be keyword only.
Thanks for the review, I have made the requested changes; please review again. |
Thanks for making the requested changes! @rhettinger: please review the changes made to this pull request. |
Apologies, I had made my own PR 20556 before remembering that this one existed. We should reconcile the two — each has tests the other doesn't, also there are some doc improvements in each that aren't in the other. Am having second thoughts about including reversed because it doubles the complexity of the code, the tests, and spills over into documentation complexity. What do you think, save reversed for another day or put it now? |
Closing in favor of #20556. |
https://bugs.python.org/issue4356