From: Reid Thompson Date: 2009-02-08T15:14:50+09:00 Subject: Re: Ruby vs Perl performance Reid Thompson wrote: > > Ruby Elapsed 0.045477 > > #!/usr/local/bin/ruby require 'rubygems' require 'inline' BAILOUT = 16 MAX_ITERATIONS = 1000 class Mandelbrot def initialize puts "Rendering" for y in -39...39 do puts for x in -39...39 do i = iterate(x/40.0,y/40.0) if (i == 0) print "*" else print " " end end end end inline do |builder| builder.c " int iterate (double x, double y) { int BAILOUT = 16; int MAX_ITERATIONS = 1000; double cr = y-0.5; double ci = x; double zi = 0.0; double zr = 0.0; double zr2 = 0.0; double zi2 = 0.0; int i = 0; double temp = 0.0; while (1) { i += 1; temp = zr * zi; zr2 = zr * zr; zi2 = zi * zi; zr = zr2 - zi2 + cr; zi = temp + temp + ci; if ( zi2 + zr2 > BAILOUT) { return i; } if ( i > MAX_ITERATIONS) { return 0; } } }" end # def iterate(x,y) # cr = y-0.5 # ci = x # zi = 0.0 while(1) # 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 time = Time.now Mandelbrot.new puts puts "Ruby Elapsed %f" % (Time.now - time)