Re-benchmark num_digits_fast against num_digits_faster after the boundary fix

オープン 初心者向け
#15,763 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
performance

調査の方向性

maths/number_of_digits.pyを読み、3つの実装を比較してください。その後、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分
マージ済み PR(30日)
4

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TheAlgorithms/Python のほかの issue

TheAlgorithms/Python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。