Skip to content

Instantly share code, notes, and snippets.

@rdp
Created June 14, 2010 18:23
Show Gist options
  • Select an option

  • Save rdp/438058 to your computer and use it in GitHub Desktop.

Select an option

Save rdp/438058 to your computer and use it in GitHub Desktop.
BAILOUT = 16
MAX_ITERATIONS = 1000
class Bench1
def initialize
puts "Rendering..."
for y in -39..39
print "\n"
for x in -39..39
i = iterate x/40.0, y/40.0
if i == 0 then print "*" else print " " end
end
end
end
def iterate(x,y)
cr = y-0.5
ci = x
zi = zr = 0.0
i = 0
while true
i += 1
temp = zr * zi
zr2 = zr * zr
zi2 = zi * zi
zr = zr2 - zi2 + cr
zi = temp + temp + ci
return i if zi2 + zr2 > BAILOUT
return 0 if i > MAX_ITERATIONS
end
end
end
20.times { |n|
puts n
time = Time.now
Bench1.new
puts "\nRuby Elapsed %.3f" % (Time.now - time)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment