zsh-users
 help / color / mirror / code / Atom feed
* while read; problems
@ 2005-04-22 12:22 Mariusz Gniazdowski
  2005-04-22 14:36 ` DervishD
  2005-04-25 10:14 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Mariusz Gniazdowski @ 2005-04-22 12:22 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-04-25 10:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-22 12:22 while read; problems Mariusz Gniazdowski
2005-04-22 14:36 ` DervishD
2005-04-25 10:14 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).