You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Re-benchmark num_digits_fast against num_digits_faster after the boundary fix #15763
PR #15761 (fixing #15754) makes num_digits_fast in maths/number_of_digits.py exact by adding a correction step after math.log10. The correction computes 10 ** (digits - 1) and 10**digits, which are big-integer powers and add cost for large inputs.
In a quick local timing on 2**100 (200,000 calls with timeit), the corrected approach took about 0.148 s, versus about 0.035 s for len(str(abs(n))). So the function named "fast" may no longer be the fastest of the three.
Re-run benchmark() in the file and record the results for all three functions.
If num_digits_fast is no longer faster, update its docstring to say it is a log10-based approach, or rename or reorder the functions so the names match the results.
Add a note on the int-to-string length limit: len(str(n)) raises ValueError for ints above about 4300 digits by default in Python 3.11+, while the log10 approach avoids it. That is a reason to keep it.
I'm happy to open a PR for the docstring and benchmark update after #15761 lands.
Activity