Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

while read; problems



Hello.
I wrote function for searching longest line:

function count {
        local line max=0 idx=0 maxidx=0
        while read line; do
                line=${#line}
                (( idx++ ))
                [[ $max -lt $line ]] && { max=$line; maxidx=$idx; }
        done < "$1"
        echo "$max in line nr: $maxidx" 
}                         

First problem: this runs much faster on bash.

zsh# du -sh somefile.bin 
6,9M    somefile.bin
zsh# time ( count somefile.bin )
2,63s user 8,51s system 96% cpu 11,585 total


bash# time { count somefile.bin ;}
2501 in line nr: 9106

real    0m4.061s
user    0m3.682s
sys     0m0.222s


So 4 seconds compared to 11.5. There were tests where bash finished in 6 seconds and zsh in 21.


Second problem: zsh results differ from run to run. I had results like:
6097 in line nr: 169
6553 in line nr: 300
etc.

Bash always returns one result: 2501 in line nr: 9106

This file was binary, but i did'nt output it, or pass it to any function (in variable). It was 
only: readed line by line and counted.

-- 
Mariusz Gniazdowski

----------------------------------------------------------------------
PS. Zdjecia samochodow, bardzo duzo, bardzo fajne galerie... 
>>> http://link.interia.pl/f1877



Messages sorted by: Reverse Date, Date, Thread, Author