headius (owner)

Revisions

gist: 215381 Download_button fork
public
Public Clone URL: git://gist.github.com/215381.git
Embed All Files: show embed
bench_fractal.duby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.lang.System
 
def run
  puts "Rendering"
  y = -39.0
  while y <= 39.0
    puts ''
    x = -39.0
    while x <= 39.0
      i = iterate(x/40.0,y/40.0)
      if (i == 0)
        print "*"
      else
        print " "
      end
      x += 1
    end
    y += 1
  end
  puts ''
end
 
def iterate(x:double,y:double)
  cr = y-0.5
  ci = x
  zi = 0.0
  zr = 0.0
  i = 0
 
  result = 0
  while true
    i += 1
    temp = zr * zi
    zr2 = zr * zr
    zi2 = zi * zi
    zr = zr2 - zi2 + cr
    zi = temp + temp + ci
    if (zi2 + zr2 > 16)
      result = i
      break
    end
    if (i > 1000)
      result = 0
      break
    end
  end
 
  result
end
 
i = 0
while i < 10
  start = System.currentTimeMillis
  run
  puts 0.001 * (System.currentTimeMillis - start)
  i += 1
end
 
diff from bench_fractal.rb #
1
2
3
4
5
6
7
8
9
10
11
12
--- bench_fractal.rb 2009-10-21 14:21:19.000000000 -0500
+++ bench_fractal.duby 2009-10-21 14:20:24.000000000 -0500
@@ -20,7 +20,7 @@
   puts ''
 end
 
-def iterate(x,y)
+def iterate(x:double,y:double)
   cr = y-0.5
   ci = x
   zi = 0.0