From: Julian Leviston Date: 2009-02-09T00:09:52+09:00 Subject: Re: Ruby vs Perl performance You could also look into The project to concert ruby to obj-c which is compiled. Am I dreaming? I can't remember the name Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 08/02/2009, at 10:09 AM, "William James" wrote: > William James wrote: > >> Vetrivel Vetrivel wrote: >> >>> I have downloaded perl and ruby program in net.I run both the >>> programs.But the Ruby program performance very wost than perl.Can >>> any one tell me the reasons and >>> soultion to make ruby as faster than perl. >>> I have attached perl program. >>> >>> >>> #!/usr/local/bin/ruby >>> >>> 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) >> >> Don't indent so deeply. It makes the code much harder to read. >> >> Don't write a mandelbrot program in an interpreted language. >> Write it in a compiled language like OCaml. > > OCaml: > > let bailout = 16.0 > let max_iterations = 1000 > > let iterate x y = > let cr = y -. 0.5 and > ci = x and > zi = 0.0 and > zr = 0.0 in > let rec iterate2 zi zr i = > if i > max_iterations then > 0 > else > let temp = zr *. zi and > zr2 = zr *. zr and > zi2 = zi *. zi in > if zi2 +. zr2 > bailout then > i > else > iterate2 (temp +. temp +. ci) (zr2 -. zi2 +. cr) (i + 1) > in > iterate2 zi zr 1 > > let mandelbrot = > for y = -39 to 38 do > print_endline ""; > for x = -39 to 38 do > let i = iterate > (float_of_int x /. 40.0) (float_of_int y /. 40.0) in > print_string ( if 0 = i then "*" else " " ) > done > done > > > let _ = mandelbrot >