Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-130167: Improve speed of _pydecimal._all_zeros and _pydecimal._exact_half by replacing re#132065
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
Marius-Juston commented Apr 4, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eendebakpt commented Apr 4, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I have some doubts this is worthwhile. The |
Lib/_pydecimal.py Outdated
| _all_zeros = re.compile('0*$').match | ||
| _exact_half = re.compile('50*$').match | ||
| # Checks for regex 0*$ | ||
| def _all_zeros(d_int,prec=0): |
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.
Do we need the prec argument?
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.
yes we need it, since when it gets called in:
def_round_down(self, prec): """Also known as round-towards-0, truncate."""if_all_zeros(self._int, prec): return0else: return-1and
def_round_half_up(self, prec): """Rounds 5 up (away from 0)"""ifself._int[prec] in'56789': return1elif_all_zeros(self._int, prec): return0else: return-1they both need the argument
Co-authored-by: Pieter Eendebak <[email protected]>
Co-authored-by: Pieter Eendebak <[email protected]>
Marius-Juston commented Apr 4, 2025
with the new while loop ( should have done this method first lol ) |
Marius-Juston commented Apr 4, 2025
With the new while loop method for the |
Marius-Juston commented Apr 4, 2025
This is probably not a bottleneck in actual computation ( it's a nice and easy optimization for sure ) and i was planning to use public methods later for benchmarking ( separating them this way though made it simpler to optimize individually ). And yeah I was planning to do larger numbers as well to test this out with repeating patterns as well to see. ( though since the prec sets the initial location of the Though these addition benchmarks will take me some time to do since I will be very busy, so if you wanted to test it yourself feel free! |
picnixz commented Apr 4, 2025
I don't think this change needs to be done. |
skirpichev commented Apr 4, 2025
If so, hardly it's a "nice optimization". E.g. the re dependency is not removed. BTW, what's you use case for the pure-Python decimal module? In most cases, people will just use C-coded extension. |
Marius-Juston commented Apr 4, 2025
Fair enough, I don't actually have a use case for the _pydecimal I was just looking through files and functions to see if there was anything that interested me |
Benchmark for all zeros
Benchmark for exact half
The tests benchmarks
reuses #130167