[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby vs Perl performance

Vetrivel Vetrivel

2/7/2009 1:35:00 PM

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)
if (i == 0)
print "*"
else
print " "
end
end
end
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

end

time = Time.now
Mandelbrot.new
puts
puts "Ruby Elapsed %f" % (Time.now - time)

zr = 0.0
i = 0

Attachments:
http://www.ruby-...attachment/3271/performa...

--
Posted via http://www.ruby-....

62 Answers

Peter Hickman

2/7/2009 2:43:00 PM

0

Can't be done. Unless you intend to build your own super fast vm.

On my box Perl consistently runs in around 2 seconds, Ruby takes 9.

There is nothing that can be done to the source (other than getting
the code to actually compile - your source is broken) that can improve
more than a second or so on that performance.

Haven't tried it under JRuby though, you might experience better
performance there.

But to honest I wouldn't sweat it that Ruby is not the best tool for
this sort of thing (number crunching), my wife's car cannot best a
dragster but it gets her where she needs to be.


Roger Pack

2/7/2009 3:58:00 PM

0

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.

Try ruby 1.9?
-=r
--
Posted via http://www.ruby-....

Radoslaw Bulat

2/7/2009 4:52:00 PM

0

On Sat, Feb 7, 2009 at 2:35 PM, Vetrivel Vetrivel
<vetrivel.bksys@gmail.com> 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.
>

Did you take code form this site:
http://www.timestretch.com/FractalBenc... ?

Try it with ruby1.9.1. I get about 1.90s for perl and 2.80s for
ruby1.9.1 so it's not bad.
--=20
Pozdrawiam

Rados=B3aw Bu=B3at
http://radarek... - m=F3j blog

Radoslaw Bulat

2/7/2009 5:04:00 PM

0

On Sat, Feb 7, 2009 at 3:42 PM, Peter Hickman <peterhi@ntlworld.com> wrote:
> Haven't tried it under JRuby though, you might experience better performa=
nce
> there.
>

JRuby is faster than 1.9 even without warming. ~2s for jruby, ~2.8s
for ruby1.9.1. With warm up it goes down to ~1.2s and with --fast flag
to ~0.75s.


--=20
Pozdrawiam

Rados=B3aw Bu=B3at
http://radarek... - m=F3j blog

Tim Greer

2/7/2009 6:15:00 PM

0

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.
>

You're not going to make it run faster (not at this time anyway). You
can always likely improve and code more efficiently, but some things
are just going to be faster.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!

Igor Pirnovar

2/7/2009 6:22:00 PM

0

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.


Ruby and Perl are two totally different programing environments and are
really not to be compared with regards to their run time performance.
With Ruby the performance issue is shifted to the entire project life
cycle, and indeed to the complexity of the project. Mere execution time
of an application represents only a tiny fraction of what is truly
measured when comparing procedural language like Perl and object
oriented Ruby. If you compare the two languages in this respect Perl
doesn't come even close to where Ruby stands. In fact I believe if you
look at performance issues from this angle, Ruby stands out very proudly
as the best performing programming language of all times.
--
Posted via http://www.ruby-....

William James

2/7/2009 9:10:00 PM

0

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.

Thomas Preymesser

2/7/2009 10:34:00 PM

0

2009/2/7 Vetrivel Vetrivel <vetrivel.bksys@gmail.com>:
> I have downloaded perl and ruby program in net.I run both the

choose the right tool for a job!

If i had a programming task which needs special attention to speed
and/or security i would choose Ada and not Ruby.

On the other hand i have written a Ruby program which uploads pictures
to several stock photo sites. In this program it is almost completely
useless to optimize for a maximum speed of the program itself because
the bottleneck is the uploading of the pictures and some manual
editing of the pictures at the website. In this case i don't care if
the rotation of a single picture take some seconds more in Ruby, so i
took Ruby because it was more fun to write the program in Ruby.

-Thomas

--
Thomas Preymesser
thopre@gmail.com
http://thopre.google...
http://thopre.word...

William James

2/7/2009 11:02:00 PM

0

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

Igor Pirnovar

2/7/2009 11:07:00 PM

0

William James wrote:
> Vetrivel Vetrivel wrote:
> 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, Ada, C, C#, Perl, French ... I think all of these things are
rather misplaced here. Isn't this about Ruby? The fact is that one needs
to choose a language that best meets their project requirements,
however, it does not seem that Vetrivel was searching for a language,
he was not happy with Ruby performance, full stop! He more likely is
searching for answers in general, and he as also some who responded, do
not quite understand what are the drawbacks and what are the true
benefits of using such a powerful tool as Ruby. Ruby is setting the
standards of contemporary computing. C#, which is in many ways a clone
of Ruby is evidently is a prominent proof of this. Still, nothing comes
close to the simplicity, elegance, power and indeed the overall
performance and primarily the productivity of designers and programmers
that work with Ruby.
--
Posted via http://www.ruby-....