| """
FractalBenchmark.cobra - print an image of the Mandelbrot set
See http://www.timestretch.com/FractalBenchmark.html
== History
2009-03-09 Csaba Urbaniczky
2009-03-09 Tests
With float:: 48-128 ms (in SciTE)
With float & Try Catch &:48-128 ms = same!
With decimal & Try Catch 6.05 - 6.06 s = very much slower!
VB.NET 2005 version on the same computer: 175-180 ms
2009-03-10 Code cleanup by Charles Esterbrook
"""
@number float
class Program
const bailOut = 16
const maxIterations = 1_000
def mandelbrot
for y in -39 : 39
print
for x in -39 : 39
if .calc(x/40, y/40), c = '*'
else, c = ' '
print c stop
def calc(ci as number, y as number) as bool
cr = y - 0.5
zr = zi = 0.0
for i in 0 : .maxIterations
zr2 = zr * zr
zi2 = zi * zi
if zi2 + zr2 > .bailOut, return false
temp = zr * zi
zr = zr2 - zi2 + cr
zi = temp + temp + ci
return true
def main
sw = System.Diagnostics.Stopwatch()
sw.start
.mandelbrot
sw.stop
print
print 'Cobra elapsed: [sw.elapsedMilliseconds] ms'
|