zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <zsh@dervishd.net>
To: zsh-users@sunsite.dk
Subject: Re: while read; problems
Date: Fri, 22 Apr 2005 16:36:59 +0200	[thread overview]
Message-ID: <20050422143659.GC7326@DervishD> (raw)
In-Reply-To: <20050422122206.GA11327@globtel.pl>

    Hi Mariusz :)

 * Mariusz Gniazdowski <cellsan@interia.pl> dixit:
> 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.

    Don't know why :? Here your function applied to a binary file
31MB in size results in 26 seconds in zsh, 14 in bash, so it's true,
the difference is noticeable. Unfortunately not both shells consider
a 'line' the same in a binary file (more in this subject below), and
bash may be reading longer lines and doing much less I/O :???
 
> Second problem: zsh results differ from run to run. I had results like:
> 6097 in line nr: 169
> 6553 in line nr: 300
> etc.

    Not reproduceable here. I always have the same, consistent
result.
 
> 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.

    The problem with binary files is: what's a line? Some arbitrary
stream of characters until a '\n' is found? Some arbitary stream of
characters that ends in a '\0'? Your measurement is incorrect because
you don't make sure what's in $IFS, and 'read' uses $IFS. You cannot
do such things on binary files from a shell script.

    Just out of curiosity: why are you messing with lines in a binary
file? Maybe you can do what you want in a faster and more portable
way. If you tell us, maybe we can help :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...


  reply	other threads:[~2005-04-22 14:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-22 12:22 Mariusz Gniazdowski
2005-04-22 14:36 ` DervishD [this message]
2005-04-25 10:14 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050422143659.GC7326@DervishD \
    --to=zsh@dervishd.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).