| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
I have some doubts this is worthwhile. The _all_zeros is indeed faster, but is that a bottleneck in actual computations? I would like to see at least a benchmark with a public method from the decimal module and a benchmark with huge numbers. |
Sorry, something went wrong.
| _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.
Do we need the prec argument?
Sorry, something went wrong.
There was a problem hiding this comment.
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):
return 0
else:
return -1and
def _round_half_up(self, prec):
"""Rounds 5 up (away from 0)"""
if self._int[prec] in '56789':
return 1
elif _all_zeros(self._int, prec):
return 0
else:
return -1they both need the argument
Sorry, something went wrong.
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
with the new while loop ( should have done this method first lol ) |
Sorry, something went wrong.
With the new while loop method for the _exact_half as well |
Sorry, something went wrong.
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 match or the while loop it does not actually really matter how large the number is but really what the precision is ) 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! |
Sorry, something went wrong.
|
I don't think this change needs to be done. _pydecimal is only used as a fallback when the decimal C extension is not available. In addition, this is not really better from a readability PoV, so I would prefer keeping this as is. |
Sorry, something went wrong.
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. |
Sorry, something went wrong.
|
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 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Benchmark for all zeros
Benchmark for exact half
The tests benchmarks