tech-userlevel archive

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

Re: mksh import



,--- Christopher Berardi (Wed, 5 Jan 2011 22:26:33 -0500) ----*
| 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
|
`-------------------------------------------------------------*

My results, with the corrected (and modified) version (at the bottom):

========================================
FreeBSD 8.2-PRERELEASE
====================

--- /bin/sh -->

real    0m0.725s
user    0m0.264s
sys     0m0.577s
<-- /bin/sh ---

--- /usr/local/bin/bash -->

real    0m1.562s
user    0m0.760s
sys     0m0.953s
<-- /usr/local/bin/bash ---

--- /usr/local/bin/ksh -->

real    0m0.593s
user    0m0.281s
sys     0m0.409s
<-- /usr/local/bin/ksh ---

--- /usr/local/bin/ksh93 -->

real    0m0.227s
user    0m0.227s
sys     0m0.000s
<-- /usr/local/bin/ksh93 ---

========================================
AIX 3
====================

--- /bin/bsh -->
./mandelbrot3.sh: syntax error at line 35: `(' unexpected

real    0m0.002s
user    0m0.000s
sys     0m0.001s
<-- /bin/bsh ---

--- /bin/bash -->

real    0m1.980s
user    0m1.139s
sys     0m0.335s
<-- /bin/bash ---

--- /bin/ksh -->

real    0m1.262s
user    0m0.659s
sys     0m0.385s
<-- /bin/ksh ---

--- /bin/ksh93 -->

real    0m0.144s
user    0m0.090s
sys     0m0.014s
<-- /bin/ksh93 ---

========================================
Linux 2.6.18-92.el5PAE
====================

--- /bin/sh -->

real    0m2.200s
user    0m1.314s
sys     0m0.865s
<-- /bin/sh ---

--- /bin/bash -->

real    0m2.252s
user    0m1.309s
sys     0m0.928s
<-- /bin/bash ---

--- /bin/ksh -->

real    0m0.292s
user    0m0.265s
sys     0m0.005s
<-- /bin/ksh ---

--- /bin/ksh93 -->
Not found
./run.sh: line 27: /bin/ksh93: No such file or directory

real    0m0.020s
user    0m0.000s
sys     0m0.001s
<-- /bin/ksh93 ---

========================================
SunOS 5.10
====================

--- /bin/sh -->
./mandelbrot3.sh: syntax error at line 35: `(' unexpected

real    0m0.011s
user    0m0.001s
sys     0m0.006s
<-- /bin/sh ---

--- /bin/bash -->

real    0m6.729s
user    0m1.707s
sys     0m2.998s
<-- /bin/bash ---

--- /bin/ksh -->

real    0m7.696s
user    0m0.895s
sys     0m1.655s
<-- /bin/ksh ---

--- /bin/ksh93 -->
Not found
./run.sh: line 27: /bin/ksh93: No such file or directory

real    0m0.004s
user    0m0.000s
sys     0m0.003s
<-- /bin/ksh93 ---

========================================
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

case $(uname -s) in
  FreeBSD) seq=/usr/local/bin/gseq;;
  Linux) seq=/usr/bin/seq;;
  AIX) seq=/opt/freeware/bin/seq;;
  SunOS) seq=/opt/sfw/bin/seq;;
esac

range=`$seq -20 20`

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 $range; do
    for x in $range; 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- Alex -- alex-goncharov%comcast.net@localhost --



Home | Main Index | Thread Index | Old Index