|
Revision 2459, 1.0 KB
(checked in by Chuck.Esterbrook, 18 months ago)
|
|
Code cleanup.
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | """ |
|---|
| 2 | FractalBenchmark.cobra - print an image of the Mandelbrot set |
|---|
| 3 | |
|---|
| 4 | See http://www.timestretch.com/FractalBenchmark.html |
|---|
| 5 | |
|---|
| 6 | == History |
|---|
| 7 | |
|---|
| 8 | 2009-03-09 Csaba Urbaniczky |
|---|
| 9 | 2009-03-09 Tests |
|---|
| 10 | With float:: 48-128 ms (in SciTE) |
|---|
| 11 | With float & Try Catch &:48-128 ms = same! |
|---|
| 12 | With decimal & Try Catch 6.05 - 6.06 s = very much slower! |
|---|
| 13 | VB.NET 2005 version on the same computer: 175-180 ms |
|---|
| 14 | 2009-03-10 Code cleanup by Charles Esterbrook |
|---|
| 15 | """ |
|---|
| 16 | |
|---|
| 17 | @number float |
|---|
| 18 | |
|---|
| 19 | class Program |
|---|
| 20 | |
|---|
| 21 | const bailOut = 16 |
|---|
| 22 | const maxIterations = 1_000 |
|---|
| 23 | |
|---|
| 24 | def mandelbrot |
|---|
| 25 | for y in -39 : 39 |
|---|
| 26 | print |
|---|
| 27 | for x in -39 : 39 |
|---|
| 28 | if .calc(x/40, y/40), c = '*' |
|---|
| 29 | else, c = ' ' |
|---|
| 30 | print c stop |
|---|
| 31 | |
|---|
| 32 | def calc(ci as number, y as number) as bool |
|---|
| 33 | cr = y - 0.5 |
|---|
| 34 | zr = zi = 0.0 |
|---|
| 35 | for i in 0 : .maxIterations |
|---|
| 36 | zr2 = zr * zr |
|---|
| 37 | zi2 = zi * zi |
|---|
| 38 | if zi2 + zr2 > .bailOut, return false |
|---|
| 39 | temp = zr * zi |
|---|
| 40 | zr = zr2 - zi2 + cr |
|---|
| 41 | zi = temp + temp + ci |
|---|
| 42 | return true |
|---|
| 43 | |
|---|
| 44 | def main |
|---|
| 45 | sw = System.Diagnostics.Stopwatch() |
|---|
| 46 | sw.start |
|---|
| 47 | .mandelbrot |
|---|
| 48 | sw.stop |
|---|
| 49 | print |
|---|
| 50 | print 'Cobra elapsed: [sw.elapsedMilliseconds] ms' |
|---|