Ruby vs Perl performance

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-forum.com/attachment/3271/performanceTime.pl

···

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

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.

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-forum.com/\.

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

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.

···

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.

--
Pozdrawiam

Radosław Bułat
http://radarek.jogger.pl - mój blog

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!

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-forum.com/\.

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.

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

···

2009/2/7 Vetrivel Vetrivel <vetrivel.bksys@gmail.com>:

I have downloaded perl and ruby program in net.I run both the

--
Thomas Preymesser
thopre@gmail.com

It's a tortoise and the hare debate really. As a C programmer i can say that
ruby is rubbish, and yet when i use it i save countless hours of debugging
and writing kludge code (When you start doing OO in C it's time to try
something new). For me it's the difference between actual productivity and
abandoning projects because i don't have time, besides i might as well chew
up some of the idle cycles my shiny new processor always seems to have.
Oh, and despite what some people might say every language has some merit.
(except cobol)

···

On Sat, Feb 7, 2009 at 11: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.

--
The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

Vetrivel Vetrivel wrote:

BAILOUT = 16

I think that this should be 4.

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.

···

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

--
Pozdrawiam

Radosław Bułat
http://radarek.jogger.pl - mój blog

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-forum.com/\.

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

Doesn't ruby 1.9 rub faster?

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

···

On 08/02/2009, at 5:19 AM, Tim Greer <tim@burlyhost.com> 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.

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!

Radosław Bułat wrote:

···

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/FractalBenchmark.html ?

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.

running on core2 duo gentoo

Ruby Elapsed 0.045477

rthompso@raker ~ $ ruby mand.rb
Rendering

                                        *
                                       ***
                                      *****
                                       ***
                                        *
                                    *********
                                  *************
                                 ***************
                              *********************
                               *******************
                             ***********************
                               *******************
                              *********************
                               *******************
                                *****************
                                 ***************
                                  *************
                                    *********
                                        *
                                 ***************
                             ***********************
                          * ************************* *
                          *****************************
                       * ******************************* *
                        *********************************
                       ***********************************
                     ***************************************
                *** ***************************************** ***
                *************************************************
                 ***********************************************
                  *********************************************
                 ***********************************************
               ***************************************************
                *************************************************
               ***************************************************
          * *************************************************** *
        ***** *************************************************** *****
        ****** *************************************************** ******
       ******* *************************************************** *******
     ***********************************************************************
     ********* *************************************************** *********
        ****** *************************************************** ******
        ***** *************************************************** *****
               ***************************************************
                *************************************************
               ***************************************************
                 ***********************************************
                   *******************************************
                    *****************************************
                  *********************************************
                 **** ****************** ****************** ****
                  *** **************** **************** ***
                   * ************** ************** *
                          *********** ***********
                          ** ***** ***** **
                           * * * *

Ruby Elapsed 0.045477

You talk as though Perl were something like Java or C++. It's not.

Development can be incredibly fast with Perl. It's just suited to
different environments and tasks than Ruby.

For the most part, it's ridiculous to talk about which language's
implementation is faster, in and of itself. The only time runtime
performance really matters that much is when you have a specific task for
which run time performance is of great specific importance -- and, even
at those times, a better algorithm is usually worth a lot more
performance gain than a faster language implementation. Because of this,
I agree that runtime performance should never be the sole determinant
when choosing which language to use for a given project. In many cases,
any language in widespread use is going to be fast enough for your needs,
and as such runtime performance should be somewhere near the *bottom* of
the list of criteria.

. . . but I really don't agree with your assessment of Perl's development
cycle as something that "doesn't even come close" to Ruby's.
Furthermore, pigeonholing Perl as a "procedural" language is as unfair to
it as pigeonholing Ruby as "object oriented" is to Ruby. Both of them
have a lot more to offer. Both provide excellent support for many
traditionally functional paradigm programming; both support object
oriented development; both can be used in a structured, procedural style
when that's the appropriate technique to employ.

In general, I enjoy programming in Ruby more, these days -- but there are
tasks for which I'd much rather write the code in Perl than in Ruby.
Each has its strengths, and each has its place in my development toolkit
(and neither of them is clearly "faster" in terms of "the entire project
life cycle", especially considering that different projects have very
different lifecycles).

···

On Sun, Feb 08, 2009 at 03:22:20AM +0900, Igor Pirnovar 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.

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.

--
Chad Perrin [ content licensed OWL: http://owl.apotheon.org ]
Quoth Sean Reifschneider: "If java had real garbage-collection, it would
delete most programs before it executed them."

Igor Pirnovar wrote:

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

"one" is singular, so it's "best meets his".

                                                  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.

Don't preach to the choir. Ruby is my favorite language.
Not even Matz would tell you to use it for mandelbrot programs.

···

--
arena, n. In politics, an imaginary rat-pit in which the
statesman wrestles with his record.
     --- Ambrose Bierce

William James wrote:

William James wrote:

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

As I said, rather misplaced discussion. This is about Ruby, not about
some obscure X-sharps which all to us look like the old spaghetti code
from 40 or so years ago when structured techniques became popular after
Pascal bursted into the scene. As for the indentation, Vetrivel clearly
has just discovered vi and Unix clones, where tab is the most prominent
feature. Almost all modern source code editors today implement
GtkSourceView widget library, which manages indentation much more
efficiently than half a century old tools, newly discovered by M$
computer illiterate folks. Lets stop babbling about various screw-sharps
and concentrate on educating newcomers about Ruby!

···

--
Posted via http://www.ruby-forum.com/\.

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)

Julian Leviston wrote:

Doesn't ruby 1.9 rub faster?

Not for that functionality comparing the two languages.

···

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