Changeset 2417
- Timestamp:
- 08/04/10 04:46:34 (18 months ago)
- Files:
-
- 1 modified
-
cobra/trunk/Samples/FractalBenchmark.cobra (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Samples/FractalBenchmark.cobra
r2129 r2417 1 1 """ 2 FractalBenchmark.cobra - print an image of the Mandelbrot set 3 2 4 See http://www.timestretch.com/FractalBenchmark.html 3 History 5 6 == History 7 4 8 2009-03-09 Csaba Urbaniczky 5 2009-03-09 Test in SciTE9 2009-03-09 Tests 6 10 With float:: 48-128 ms (in SciTE) 7 11 With float & Try Catch &:48-128 ms = same! … … 13 17 @number float 14 18 15 class Program 19 class Program 16 20 17 const bailOut = 16 21 const bailOut = 16 18 22 const maxIterations = 1_000 19 23 20 shared 21 22 def mandelbrot 23 for y in -39 : 39 24 print 25 for x in -39 : 39 26 if .calc(x/40, y/40), c = '*' 27 else, c = ' ' 28 print c stop 29 30 def calc(ci as number, y as number) as bool 31 cr = y - 0.5 32 zr = 0.0 33 zi = 0.0 34 for i in 0 : .maxIterations 35 zr2 = zr * zr 36 zi2 = zi * zi 37 if zi2 + zr2 > .bailOut, return false 38 temp = zr * zi 39 zr = zr2 - zi2 + cr 40 zi = temp + temp + ci 41 return true 42 43 def main 44 sw = System.Diagnostics.Stopwatch() 45 sw.start 46 .mandelbrot 47 sw.stop 24 def mandelbrot 25 for y in -39 : 39 48 26 print 49 print 'Cobra elapsed: [sw.elapsedMilliseconds] ms' 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'



