Re: Slow bash script
On Sunday 09 September 2007, Andrew Sackville-West wrote:
> On Sun, Sep 09, 2007 at 05:35:12PM -0400, Marty wrote:
> > Andrew Sackville-West wrote:
> >> On Sun, Sep 09, 2007 at 04:23:42PM -0400, Marty wrote:
> >>> The following script seems to run abnormally slow on a 400Mhz Sarge
> >>> system, getting only about one iteration per second in the while loop.
> >>> It extracts md5sums from a 180k Packages file and makes an indices
> >>> file. I've narrowed down the slowdown to the lines in the while loop
> >>> starting with "search=..."
> >>
> >> how have you determined this?
> >
> > I checked the output rate by outputing to stdout (instead of piping to
> > gzip after the "done" statement). I also timed it with the "time"
> > command.
>
> but, That only tells you how long it takes to iterate through the loop
> to get to the gzip command, not how much time is spent in each
> statement.
>
> smth like:
>
> while read inputline
> do echo "input line is " $inputline
> search=`grep...`
> echo "search is " $search"
> if...
> echo "we got a good search"
> fi
> ...
> done
how about ``set -x'' and let the shell do it for you ?
Reply to: