Re-benchmark num_digits_fast against num_digits_faster after the boundary fix

未關閉 適合新手
#15,763 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
72/100
Issue 類型
文件
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
python
領域
performance

研究方向

閱讀 maths/number_of_digits.py 並比較三種實作,然後在 PR #15761 合併後執行 benchmark()。記錄結果,並據此更新 docstring 或函式命名,包括文件中所述的整數轉字串位數限制;當基準測試和說明反映出測得的取捨時,工作即告完成。

由索引模型根據 Issue 內容生成。

描述

enhancement
Feature description
Feature description

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.

Proposed follow-up, once #15761 is merged:

  1. Re-run benchmark() in the file and record the results for all three functions.
  2. 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.
  3. 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.

主要語言
Python
星號
226k
分支
51.3k
平均合併
8 小時 58 分鐘
30 天內合併 PR
4

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TheAlgorithms/Python 的其他 Issue

查看 TheAlgorithms/Python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。