Ormai l' uso inutile del catpremio è molto noto, e c'è anche una menzione di un uso inutile diecho (non pertinente per questa domanda). Mi chiedo se ci dovrebbe essere un "Uso inutile di echoin Bash Award": il piping sembra essere molto più lento di heredocs e herestring secondo alcune misurazioni altamente non scientifiche:
Heredocs:
for reps in 1 2 3 do time for i in {1..1000} do cat <<'END' test string END done > /dev/null done real 0m1.786s user 0m0.212s sys 0m0.332s real 0m1.817s user 0m0.232s sys 0m0.332s real 0m1.846s user 0m0.256s sys 0m0.320sHerestrings
for reps in 1 2 3 do time for i in {1..1000} do cat <<< 'test string' done > /dev/null done real 0m1.932s user 0m0.280s sys 0m0.288s real 0m1.956s user 0m0.248s sys 0m0.348s real 0m1.968s user 0m0.268s sys 0m0.324sreindirizzamento
for reps in 1 2 3 do time for i in {1..1000} do echo 'test string' | cat done > /dev/null done real 0m3.562s user 0m0.416s sys 0m0.548s real 0m3.924s user 0m0.384s sys 0m0.604s real 0m3.343s user 0m0.400s sys 0m0.552s
In generale, heredocs e herestring hanno circa la stessa velocità (questo è solo un set di dati di diversi test) mentre il reindirizzamento è costantemente più lento di oltre il 50%. Sto fraintendendo qualcosa o potrebbe essere usato come regola generale per i comandi che leggono l'input standard in Bash?
cat <<ENDvs. cat <<< "test string"vs. echo "test string" | cato cat <<'END'vs. cat <<< 'test string'vs. echo 'test string' | catper avere la stessa quantità di espansioni eseguite dalla shell sulle stringhe.
$(seq $reps)?
seqpremio " uso inutile di " ;-)