tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: mksh import



>Please don't use paragraph-length lines.
Sorry, I thought mutt and vim were taking care of things.

>That aside, does this really work?
>
>> inmandelbrot() {
>>     mag=$(($1 * $1 + $2 * $2))
>>     if [ $mag -gt "40000" ] || [ $5 -ge $6 ]; then
>>         echo $5
>>     else
>>         r=$((($1 * $1)/100 - ($2 * $2)/100 + $3))
>>         i=$((($1 * $2)/100 * 2 + $4))
>>         cnt=$(($5 + 1))
>>         inmandelbrot r i $3 $4 $cnt $6
>>     fi
>> }
>
>That looks as though it should be $r and $i in the recursive call.
>Similarly, this
>
>>         val=$(inmandelbrot rval ival rval ival 1 10)
>
>looks as though it's missing four dollar signs.
>
>Or Am I Missing Something (tm)?
No, I think those should have dollar signs. It lacked them in the original
script that I used and I didn't catch that. It's funny, because it works 
similarly without them, it basically creates ascii art in the form resembling
Mandelbrot set. But, this new version has them in there. The worst performance 
I noticed was on Linux using bash. And the second worst was on Linux using zsh.
About twice as fast as at just over a second was Ubuntu's default dash 
(sorry I don't have the exact figures from my Linux runs). And running on my 
trusty NetBSD 5.1 system I got the following results:

========================
NetBSD 5.1
    /bin/sh:
        0.89s real
        0.37s user
        0.52s system

    /bin/ksh:
        1.05s real
        0.50s user
        0.54s system


inmandelbrot() {
    mag=$(($1 * $1 + $2 * $2))
    if [ $mag -gt "40000" ] || [ $5 -ge $6 ]; then
        echo $5
    else
        r=$((($1 * $1)/100 - ($2 * $2)/100 + $3))
        i=$((($1 * $2)/100 * 2 + $4))
        cnt=$(($5 + 1))
        inmandelbrot $r $i $3 $4 $cnt $6
    fi
}

for y in `seq -20 20`; do
    for x in `seq -20 20`; do
        rval=$((x * 10))
        ival=$((y * 10))
        val=$(inmandelbrot $rval $ival $rval $ival 1 10)
        if [ $val -eq 10 ]; then
            echo -n ".";
        else
            echo -n $val;
        fi
    done
    echo
done



-- 
Christopher Berardi
http://www.natoufa.com/

Be still, and know that I am God (Psalms 46:10)


Home | Main Index | Thread Index | Old Index