Comparison Ruby, Python, Php, Groovy ecc

Marco Mastrodonato wrote:

Comparison script languages for the fractal geometry, these are the
languages i tested:

Java
Lua 5.1.4
Php 5.3.0
Python 2.6.2
Python 3.1.1
Jython 2.5.0
Groovy 1.6.3
Jruby 1.3.1
Ruby 1.9.1 p129
Ruby 1.8.6 p368
Ruby 1.8.6 p111
IronRuby 0.9.0
IronPython 2.0.2
Perl 5.10.0

Let me know yours comment

http://mastrodonato.info/index.php/2009/08/comparison-script-languages-for-the-fractal-geometry/?lang=en

A decent try and honest, but there are too many variables involved.
Even a quick look at the Perl code could use a little fine tuning (it
looked like v4 code in a lot of ways (from 15 years ago), improperly
using local, etc.), and where there are wasteful assignments (not a big
deal). I'd recommend posting the code in their respective news groups
and asking for any advice on how to speed up the code/write it more
efficiently, and see what people come up with. Implementing the same
code essentially the same way in different languages may show a slower
time elapsed, but perhaps if you recoded it in a way to take advantage
of that language you would see some (slightly, but important)
differences in your results. Don't get me wrong, I appreciate what
you're doing here and it's a good attempt, I just think there are too
many variables. I haven't ran Windows for a long time, but I wouldn't
be surprised if a *nix variant provided different results (I know it
does for me on Linux using a very comparable system). For that matter,
you might offer something in C and C++ to compare to compiled Java,
unless you believe that those aren't viable comparison languages for
some reason? (If so, know that myself and many others develop online
and offline using them, because they are faster and sometimes that's
important with huge trafficked sites where every tiny otherwise trivial
thing makes a difference).

Marco Mastrodonato wrote:

Comparison script languages for the fractal geometry, these are the
languages i tested:

Java
Lua 5.1.4
Php 5.3.0
Python 2.6.2
Python 3.1.1
Jython 2.5.0
Groovy 1.6.3
Jruby 1.3.1
Ruby 1.9.1 p129
Ruby 1.8.6 p368
Ruby 1.8.6 p111
IronRuby 0.9.0
IronPython 2.0.2
Perl 5.10.0

Let me know yours comment

http://mastrodonato.info/index.php/2009/08/comparison-script-languages-for-the-fractal-geometry/?lang=en

A decent try and honest, but there are too many variables involved.
... Don't get me wrong, I appreciate what you're doing here and it's
a good attempt, I just think there are too many variables...
you might offer something in C and C++ to compare to compiled Java,
unless you believe that those aren't viable comparison languages for
some reason?

OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)

java Bench1 > /dev/null

Java Elapsed 0.08
Java Elapsed 0.079
Java Elapsed 0.079

ruby 1.9.2dev (2009-08-25 trunk 24642) [i686-linux]

ruby bench1.rb > /dev/null

Ruby Elapsed 3.515
Ruby Elapsed 3.352
Ruby Elapsed 3.523

jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM
1.6.0_0) [i386-java]

jruby bench1.rb > /dev/null

Ruby Elapsed 4.185
Ruby Elapsed 3.760
Ruby Elapsed 3.626

ruby 1.9.2dev (2009-08-25 trunk 24642) [i686-linux]

ruby -rubygems bench2.rb > /dev/null

Ruby Elapsed 0.059
Ruby Elapsed 0.058
Ruby Elapsed 0.060

jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM
1.6.0_0) [i386-java]

jruby -rubygems bench2.rb > /dev/null

Ruby Elapsed 0.409
Ruby Elapsed 0.410
Ruby Elapsed 0.412

require 'ffi-inliner'

BAILOUT = 16
MAX_ITERATIONS = 1000

class Bench2
  extend Inliner

  def initialize
    puts "Rendering..."
    for y in -39..39
      for x in -39..39
        print iterate(x/40.0, y/40.0) == 0 ? "*" : " "
      end
      print "\n"
    end
  end

  inline <<-EO
    int n;

    int iterate(double x, double y)
    {
      int i = 0;
      double zi = 0.0;
      double zr = 0.0;
      double zi2, zr2, temp;
      double ci = x;
      double cr = y-0.5;
      while(i < #{MAX_ITERATIONS}) {
        i++;
        temp = zr * zi;
        zr2 = zr * zr;
        zi2 = zi * zi;
        zr = zr2 - zi2 + cr;
        zi = temp + temp + ci;
        if(zi2 + zr2 > #{BAILOUT}) return i;
      }
      return 0;
    }
  EO
end

time = Time.now
Bench2.new
STDERR.puts "Ruby Elapsed %.3f" % (Time.now - time)

In this case, the original Ruby version of the method looked so much
like C that I don't think you lose much in readability by inlining
(except for loss of vim's syntax highlighting).

···

On Tue, Aug 25, 2009 at 5:20 PM, Nathan Keel<nat.k@gm.ml> wrote:

>> Comparison script languages for the fractal geometry, these are the
>> languages i tested:

http://shootout.alioth.debian.org/u32q/benchmark.php?test=mandelbrot

OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)> java Bench1 > /dev/null

Java Elapsed 0.08
Java Elapsed 0.079
Java Elapsed 0.079

ruby 1.9.2dev (2009-08-25 trunk 24642) [i686-linux]> ruby -rubygems bench2.rb > /dev/null

Ruby Elapsed 0.059
Ruby Elapsed 0.058
Ruby Elapsed 0.060

I guess this wasn't the first run when the inline code got compiled?

Anyway, since the runtime is so short, in the case of the java version
you're to some extent measuring the JVM startup time.

Another thing: if I'm not totally mistaken, a ruby float is a double
in the Java world.

jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM
1.6.0_0) [i386-java]

jruby bench1.rb > /dev/null

Ruby Elapsed 4.185
Ruby Elapsed 3.760
Ruby Elapsed 3.626

Pass --server for best performance. Additionally pass --fast to turn
on experimental optz.

jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM
1.6.0_0) [i386-java]

jruby -rubygems bench2.rb > /dev/null

Ruby Elapsed 0.409
Ruby Elapsed 0.410
Ruby Elapsed 0.412

Ditto. CPU-intensive code will often be as much as 2x faster with --server.

- Charlie

···

On Tue, Aug 25, 2009 at 5:18 PM, <brabuhr@gmail.com> wrote:

>> Comparison script languages for the fractal geometry, these are the
>> languages i tested:

http://shootout.alioth.debian.org/u32q/benchmark.php?test=mandelbrot

OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)> java Bench1 > /dev/null

Java Elapsed 0.08
Java Elapsed 0.079
Java Elapsed 0.079

ruby 1.9.2dev (2009-08-25 trunk 24642) [i686-linux]> ruby -rubygems bench2.rb > /dev/null

Ruby Elapsed 0.059
Ruby Elapsed 0.058
Ruby Elapsed 0.060

I guess this wasn't the first run when the inline code got compiled?

Right, compilation time is not included. The time measurements were
taken inside the program before and after the method call.

Anyway, since the runtime is so short, in the case of the java version
you're to some extent measuring the JVM startup time.

As above, the timings are from inside the program: so, they don't
include the startup time, but the program did not allow for JIT warmup
time.

···

On Wed, Aug 26, 2009 at 1:25 AM, lith<minilith@gmail.com> wrote:

It's unfair, result of this program can be determined at compile time,
the haskell one would be fastest ( if there is one :slight_smile:

JVM makes plenty of optimizations before it runs program, while starts
very slow. Scripts are faster if startup time is taken into
consideration.

btw, Ruby doesn't have a "char" type, doing a "char" print is of course
much slower...

···

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

One of the machines I tested on only had the client vm, so I didn't
include those numbers from the other machines either. However,
--server and --fast on the other machines didn't make much of an
impact on this short test: varying from a nice speed boost on some
runs to slower on others (the test program did not do any pre-test
warmup).

···

On Thu, Sep 3, 2009 at 1:11 AM, Charles Oliver Nutter<headius@headius.com> wrote:

On Tue, Aug 25, 2009 at 5:18 PM, <brabuhr@gmail.com> wrote:

jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM
1.6.0_0) [i386-java]

jruby bench1.rb > /dev/null

Ruby Elapsed 4.185

Pass --server for best performance. Additionally pass --fast to turn
on experimental optz.

jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM
1.6.0_0) [i386-java]

jruby -rubygems bench2.rb > /dev/null

Ruby Elapsed 0.409

Ditto. CPU-intensive code will often be as much as 2x faster with --server.

May simply be too short of a test, or the bottleneck isn't in
execution...but I'm sure with some poking around we could get JRuby to
have the fastest result.

- Charlie

···

On Thu, Sep 3, 2009 at 7:18 AM, <brabuhr@gmail.com> wrote:

Ditto. CPU-intensive code will often be as much as 2x faster with --server.

One of the machines I tested on only had the client vm, so I didn't
include those numbers from the other machines either. However,
--server and --fast on the other machines didn't make much of an
impact on this short test: varying from a nice speed boost on some
runs to slower on others (the test program did not do any pre-test
warmup).