5
1
I don't understand the results of a simple performance test I ran using two basic scripts (running on a high end server):
perfVar.zsh :
#!/bin/zsh -f
MYVAR=`cat $1`
for i in {1..10}
do
echo $MYVAR
done
perfCat.zsh
#!/bin/zsh -f
for i in {1..10}
do
cat $1
done
Performance test result:
> time ./perfVar.zsh BigTextFile > /dev/null
./perfVar.zsh FE > /dev/null 6.86s user 0.32s system 100% cpu 7.177 total
> time ./perfCat.zsh BigTextFile > /dev/null
./perfCat.zsh FE > /dev/null 0.01s user 0.10s system 91% cpu 0.118 total
I would have thought that accessing a VARIABLE was way faster than reading a FILE on the file system... Why this result ? Is there a way to optimize the perfCat.zsh script by reducing the number of accesses to the file system ?
How big is BigTextFile? And how much RAM is in the computer? – Heath – 2011-05-04T18:01:56.513
Is that a typo above? As written both scripts will cat the first command-line argument ($1) rather than the loop variable ($i). – CarlF – 2011-05-04T19:08:33.233
@CarlF No it is not a typo. I don't use the value of $i, I just want to repeat the operation 10 times (read the file $1) – Sébastien – 2011-05-05T07:42:16.863
@Heath - File is 50MB and server got 48GB RAM (1GB free). Results are similar on an other server with less RAM occupation. – Sébastien – 2011-05-05T08:07:02.223
As an aside, if you use perl/ruby/python (or something similar) instead of a shell language, you'll probably see much more comparable results. – Brian Vandenberg – 2011-05-05T16:15:50.603