mandelbrot Toit #2 program
source code
/* The Computer Language Benchmarks game
https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
transliterated from Andrey Filatkin's JavaScript #3 by Isaac Gouy
*/
import host.pipe
ITER ::= 50
LIMIT ::= 4.0
main args:
h ::= args.size == 1 ? int.parse args[0] : 200; w ::= h
print "P4\n$w $h"
bytes-per-row ::= w >> 3
initial-r ::= List w
initial-i ::= List w
inv ::= 2.0 / w
for xy := 0; xy < w; xy++:
i := inv * xy
initial-r[xy] = i - 1.5
initial-i[xy] = i - 1.0
for y := 0; y < h; ++y:
row := ByteArray bytes-per-row
for x-byte := 0; x-byte < bytes-per-row; x-byte++:
ci := initial-i[y]
res := 0
for i := 0; i < 8; i += 2:
x := x-byte << 3
cr1 := initial-r[x + i]
cr2 := initial-r[x + i + 1]
zr1 := cr1
zi1 := ci
zr2 := cr2
zi2 := ci
b := 0
for j := 0; j < ITER; j++:
tr1 ::= zr1 * zr1
ti1 ::= zi1 * zi1
zi1 = 2 * zr1 * zi1 + ci
zr1 = tr1 - ti1 + cr1
if tr1 + ti1 > LIMIT:
b |= 2
if b == 3: break
tr2 ::= zr2 * zr2
ti2 ::= zi2 * zi2
zi2 = 2 * zr2 * zi2 + ci
zr2 = tr2 - ti2 + cr2
if tr2 + ti2 > LIMIT:
b |= 1
if b == 3: break
res = (res << 2) | b
row[x-byte] = ~res
pipe.stdout.write row
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
v2.0.0-alpha.146
Wed, 24 Apr 2024 22:48:35 GMT
MAKE:
cp -r Include/toit/.packages .
cp -r Include/toit/package.lock .
cp -r Include/toit/package.yaml .
/opt/src/toit/bin/toit.compile -O2 --strip -o mandelbrot.toit-2.toit_run mandelbrot.toit-2.toit
1.45s to complete and log all make actions
COMMAND LINE:
./mandelbrot.toit-2.toit_run 16000
(BINARY) PROGRAM OUTPUT NOT SHOWN