Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

string/concatenation.rb tests are misleading

Aperta
#64 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
ruby

Direzione di ricerca

Inizia in string/concatenation.rb e analizza come gli attuali benchmark definiscono il metodo veloce e confrontano i metodi di concatenazione. Usa come riferimento l’esempio benchmark-ips dell’issue, con variabili di runtime per il confronto; il lavoro è completato quando il benchmark non tratta più la concatenazione eseguita in fase di parsing come un’operazione di runtime e confronta equamente le alternative indicate.

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

Descrizione

Hi, the tests in string/concatenation.rb are quite misleading.

The fast method consists of this

def fast
  'foo' 'bar'
end

That's not concatenating during calling of fast but on parsing the code. If you write another method just returning foobar, it is as fast as this method.

So I think this is not fair comparison and what you usually want is to concatenate two variables during runtime.

For this use case concat and << are calling the same code, so they have the same performance and both are fine if you want to change the string on the left and not just get two strings concatenated. If you want a new string you can use +.

Some better test could be to compare + and String interpolation

Benchmark.ips do |x|
  foo = 'foo'
  bar = 'bar'

  x.report('String#+') do
    foo + bar
  end

  x.report('String interpolation') do
    "#{foo}#{bar}"
    end

  x.compare!
end

This still has the difference that interpolation can handle nil values, while + cannot.

Lingua principale
Ruby
Stelle
5.7k
Fork
370
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

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 fastruby/fast-ruby

Tutte le issue di fastruby/fast-ruby

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.