Peter Tribble wrote:
On Thu, Sep 10, 2009 at 8:38 AM, Raymond Wong<raym...@gmail.com> wrote:
Hi,
Thanks for taking a look.
The SPARC system is a Sun V440 with 4 CPUs and 16GB of RAM. The normal CPU load
is about 50% and minimal disk activity.
What the script does is to go through a text file and get the beginning &
ending line # for printing the pages specified. The part of the script that is
taking over 20min on Solaris is quoted here.
I ran the script in the /tmp folder on both the Solaris & Linux systems.
[code]
#!/usr/bin/bash
#
# set -x
#
#
authen=$1
prt_req_id=82044908
page_from=200
page_to=250
printer=nec_p2000
copies=0
printed=1
file_dir=./
org_file=o${prt_req_id}.out
dest_file=o${prt_req_id}.prt
line=0
page=1
BeginLine=1
EndLine=0
page_to=`echo ${page_to} + 1 | bc`
echo `date`
echo "Calculating line numbers."
while read a
do
line=`echo ${line} + 1 | bc`
if [ "`echo ${a} | cut -b1`" = ^L ]
then
page=`echo ${page} + 1 | bc`
if [ ${page_from} -eq ${page} ]
then
BeginLine=`echo ${line} | bc`
fi
if [ ${page_to} -eq ${page} ]
then
EndLine=`echo ${line} - 1 | bc`
break
fi
fi
done<<list
`cat ${file_dir}/${org_file}`
list
[/code]
Ouch. Don't increment variables like that.
As a quck test using ksh to count the line in my messages file (about
1600). Doing it this way:
while read a
do
line=`echo ${line} + 1 | bc`
done
takes
real 8.855
user 1.440
sys 6.254
while doing it this way:
while read a
do
line=$(($line+1))
done
takes
real 0.062
user 0.054
sys 0.006
as you can see, the difference is substantial.
Indeed, and perhaps you should point out that bash(1) shows the same
order of difference, but I wouldn't stop there. The author of the script
seems to have an obsession with backticks, and then running external
commands in them too!
As important as the increment (because it happens every iteration fo the
loop) is...
if [ "`echo ${a} | cut -b1`" = ^L ]
then
.
.
.
fi
Which could be replaced with...
case $a in
*^L*)
.
.
.
esac
Then there's...
done<<list
`cat ${file_dir}/${org_file}`
list
Why can't it just be...
done<${file_dir}/${org_file}
Then there's...
BeginLine=`echo ${line} | bc`
Why not just...
BeginLine=line
Even...
`date`
Should be just...
date
But this may just sound like sour grapes. The sad reality is that Linux
is often better at running bad code well, whereas Solaris doesn't suffer
fools gladly.
I think one potential reason for the difference is that Solaris has a
different implementation of bc(1) which actually spawns dc(1) as a
subprocess.
There may also be differences in other commands (including bash(1)) and
in the PATH.
_______________________________________________
perf-discuss mailing list
perf-discuss@opensolaris.org