Re-benchmark num_digits_fast against num_digits_faster after the boundary fix

Aperta Adatta ai principianti
#15,763 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
performance

Direzione di ricerca

Leggi maths/number_of_digits.py e confronta le tre implementazioni. Poi esegui benchmark() dopo il merge di PR #15761. Registra i risultati e aggiorna il docstring o i nomi delle funzioni in modo che corrispondano, compreso il limite di cifre documentato per la conversione da intero a stringa; il lavoro è completato quando il benchmark e la spiegazione riflettono i compromessi misurati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
226k
Fork
51.3k
Merge medio
8h 58m
PR unite (30g)
4

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TheAlgorithms/Python

Tutte le issue di TheAlgorithms/Python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.