Hirdetés

Keresés

Új hozzászólás Aktív témák

  • F34R

    nagyúr

    válasz Rimuru #6934 üzenetére

    o do that, shells fork the command in a subshell and read its output through a pipe or socketpair. You see a lot of variation here. On a 50MiB file here, I can see for instance bash being 6 times as slow as ksh93 but slightly faster than zsh and twice as fast as yash.

    The main reason for bash being slow is that it reads from the pipe 128 bytes at a time (while other shells read 4KiB or 8KiB at a time) and is penalised by the system call overhead.

    zsh needs to do some post-processing to escape NUL bytes (other shells break on NUL bytes), and yash does even more heavy-duty processing by parsing multi-byte characters.

    All shells need to strip the trailing newline characters which they may be doing more or less efficiently.

    Some may want to handle NUL bytes more gracefully than others and check for their presence.

    Then once you have that big variable in memory, any manipulation on it generally involves allocating more memory and coping data across.

    Here, you're passing (were intending to pass) the content of the variable to echo.

    Luckily, echo is built-in in your shell, otherwise the execution would have likely failed with an arg list too long error. Even then, building the argument list array will possibly involve copying the content of the variable.

    The other main problem in your command substitution approach is that you're invoking the split+glob operator (by forgetting to quote the variable).

    For that, shells need to treat the string as a string of characters (though some shells don't and are buggy in that regard) so in UTF-8 locales, that means parsing UTF-8 sequences (if not done already like yash does), look for $IFS characters in the string. If $IFS contains space, tab or newline (which is the case by default), the algorithm is even more complex and expensive. Then, the words resulting from that splitting need to be allocated and copied.

    The glob part will be even more expensive. If any of those words contain glob characters (*, ?, [), then the shell will have to read the content of some directories and do some expensive pattern matching (bash's implementation for instance is notoriously very bad at that).

    Nem volt hulyeseg azt mondani probald ki a mksh-t. A fish meg a zsh-tol is lassabb.

    Az i valtozo a scriptben pl egy nagy eroforras, ezt lassan fogja neked futtatni.

  • F34R

    nagyúr

    válasz Rimuru #6934 üzenetére

    Van prezto-d vagy valami nagyobb kiegeszitod? nezd meg bash-al is, atvaltassz egyszeruen lefuttatod.

Új hozzászólás Aktív témák