-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Speed up binary shifting operators #90213
Comments
See its PR. --------- Inspired by bpo-44946, I found there were no special shortcuts for shifting operation applied to "medium value" long object. So I modified CPython's VM to accelerate my python project where there is plenty of binary shifting operation. I guess somebody else might also need it. |
Could you please show any microbenchmarking results? |
I post a comment to the PR showing its performance improvement. I paste it below. I think the result not bad. ------------- I use timeit to measure time costs and any other operators or calls are excluded. For each testcase, the former is dcd2796 and the latter is this PR's base 036bbb1. 64-bit Release building. Run in Windows 10 1709 (64-bit) python -m timeit " i = 1; i <<= 3; i >>= 3" # small value (cost down by 36%) python -m timeit " i = 1; i <<= 10; i >>= 10" # medium value (-25%) python -m timeit " i = 1; i <<= 100; i >>= 100" # big value (-12%) |
Two separate significant improvements have been pushed: thanks, Xinhang Xu! The original PR also contained a reworking of the general case for right-shifting a negative integer. The current code (in main) for that case does involve some extra allocations, and it ought to be possible to write something that doesn't need to allocate temporary PyLongs. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: