I was trying to determine the best performance for string fill like in:
str+="A"
#one per loop
I came with this script for bash:
#!/bin/bash
bReport=false
nLimit=${1-3000}; #up to 25000
echo "nLimit='$nLimit'"
shopt -s expand_aliases
nStop=100000;fMaxWorkTime=1.0;
alias GetTime='date +"%s.%N"';
nTimeBegin="`GetTime`";
nDelayPart="`GetTime`";
strFinal="";
str="";
fPartWorkSleep="`bc <<< "scale=10;($fMaxWorkTime/$nStop)*$nLimit"`"
echo "fPartWorkSleep='$fPartWorkSleep'"
nCount=0;
while true;do
str+="A";
((nCount++))&&:;
if(((nCount%nLimit)==0)) || ((nCount==nStop));then
strFinal+="$str";
str="";
if $bReport;then
echo "`bc <<< "$(GetTime)-$nDelayPart"` #${#strFinal} #`bc <<< "$(GetTime)-$nTimeBegin"`";
nDelayPart="`GetTime`";
fi
sleep $fPartWorkSleep # like doing some weigthy thing based on the amount of data processed
fi;
if((nCount==nStop));then
break;
fi;
done;
echo "strFinal size ${#strFinal}"
echo "took `bc <<< "$(GetTime)-$nTimeBegin"`"
And in bash the best performance/size is when str
is limited from 3000 to 25000 characters (on my machine). After each part is filled, it must be emptied and some weigthy action can be performed with str
value (and the weight is relative to its size).
So my question is, what shell has the best string fill performance? based on what I exposed. I am willing to use other shell than bash, just for this kind of algorithm, it if proves to be faster.
PS.: I had to use nCount as checks on string size degraded performance.
str+="A"
? http://paste.ubuntu.com/14124037/ – muru Dec 21 '15 at 02:27bc
each time you empty the string. How do you compensate for that? – muru Dec 21 '15 at 03:07"$value$fill$fill$fill"
and so on. it's what i do withset
andshift
- i just get as many empty positional parameters as i need to make it to 40k and then change$IFS
to whatever the filler char should be. and if$IFS
were changed again the whole 30 some thousand char string would just change each time$*
expanded. – mikeserv Dec 21 '15 at 03:07bc
asdate
, well pointed, let me check.. – Aquarius Power Dec 21 '15 at 03:12