Ruby performance question

Hello,

I am not a performance freak at all but I've noticed that despite a huge difference between a single CPU 1GHz G4 and a dual 2 GHz G5, both running ruby 1.8.2 with 1GB of RAM on Mac OS X 10.3.8, there was only a 33% difference in the calculation of a factorial:
I used the following code:
#!/usr/local/bin/ruby
class Integer
   def factorial
     (1..self).inject(1) { |f, n| f * n }
   end
end

puts 100000.factorial

It takes about 9 minutes on the lower profile machine and 6 min or so on
the bigger one.

Generally, the generation of processor (G4 vs. G5) alone is responsible of a similar difference at equal clock frequencies. But here, I expected a bigger difference given the combined effect of a higher clock, a higher generation and a dual CPU.

BTW, I was not able to make a comparable test on my 2.6 GHz 1GB Windows XP SP2 workstation which failed at 9273.factorial. I don' t remember the message but it's easy to reproduce.

Is this kind of performance "normal" given the algorithm used or is there a balance between the coding style and the performances that could be wise to consider?

I have no performance objective, I am just curious.

Thank you for your advices,
Jean-Pierre

Jaypee wrote:

Generally, the generation of processor (G4 vs. G5) alone is responsible of a similar difference at equal clock frequencies. But here, I expected a bigger difference given the combined effect of a higher clock, a higher generation and a dual CPU.

I don't think Ruby takes advantage of the 2nd CPU. The script runs on only 1 CPU, so all the benefit you're seeing is from the faster clock speed.

A second processor is only going to be of benefit when multiple threads/processes are running at the same time. That's not the case here. If fact, since Ruby's threads are currently "in process", Ruby will always run on a single processor. Of course, if your computer is doing some other work while running your Ruby script, it should get scheduled on the other processor and not slow you down.

James Edward Gray II

···

On Mar 28, 2005, at 6:39 AM, Jaypee wrote:

Generally, the generation of processor (G4 vs. G5) alone is responsible of a similar difference at equal clock frequencies. But here, I expected a bigger difference given the combined effect of a higher clock, a higher generation and a dual CPU.

Jaypee a écrit :

Hello,

I am not a performance freak at all but I've noticed that despite a huge difference between a single CPU 1GHz G4 and a dual 2 GHz G5, both running ruby 1.8.2 with 1GB of RAM on Mac OS X 10.3.8, there was only a 33% difference in the calculation of a factorial:
I used the following code:
#!/usr/local/bin/ruby
class Integer
  def factorial
    (1..self).inject(1) { |f, n| f * n }
  end
end

puts 100000.factorial

It takes about 9 minutes on the lower profile machine and 6 min or so on
the bigger one.

Generally, the generation of processor (G4 vs. G5) alone is responsible of a similar difference at equal clock frequencies. But here, I expected a bigger difference given the combined effect of a higher clock, a higher generation and a dual CPU.

BTW, I was not able to make a comparable test on my 2.6 GHz 1GB Windows XP SP2 workstation which failed at 9273.factorial. I don' t remember the message but it's easy to reproduce.

Is this kind of performance "normal" given the algorithm used or is there a balance between the coding style and the performances that could be wise to consider?

I have no performance objective, I am just curious.

Thank you for your advices,
Jean-Pierre

Thank you for your comments. I'd like to clear the point about Windows XP SP2: It works well, I could run the script from a command line (former tests were done using Eclipse and rdt) and it took 7 minutes on a P4@2.6 Ghz + 1 GB RAM
As I happended to have access to those similar platforms in terms of RAM and CPU, I just wanted to compare them and have an idea of performances using Ruby.
J-P

Tim Hunter wrote:

I don't think Ruby takes advantage of the 2nd CPU. The script runs on only 1 CPU, so all the benefit you're seeing is from the faster clock speed.

And since P-IVs are hyper-threaded, the actual CPU utilization on a two-stones server is probably only 25%.

···

--
Best regards,

Alexey Verkhovsky

Ruby Forum: http://ruby-forum.org (moderator)
RForum: http://rforum.andreas-s.net (co-author)
Instiki: http://instiki.org (maintainer)

So that explains part of it.

But why would a 2GHz G5 not be at least twice as fast as a 1GHz G4?

G5 versus G4 aside, the doubling of the clock rate alone should suffice, no?

I'll have to run the test myself on my 1GHz G4 laptop versus my 2GHz G5 desktop...as soon as my wife stops playing WoW on the latter :slight_smile:

···

On Mar 28, 2005, at 6:49 AM, Tim Hunter wrote:

Jaypee wrote:

Generally, the generation of processor (G4 vs. G5) alone is responsible of a similar difference at equal clock frequencies. But here, I expected a bigger difference given the combined effect of a higher clock, a higher generation and a dual CPU.

I don't think Ruby takes advantage of the 2nd CPU. The script runs on only 1 CPU, so all the benefit you're seeing is from the faster clock speed.

Gavin Kistner wrote:

But why would a 2GHz G5 not be at least twice as fast as a 1GHz G4?

Because there may be all sorts of things other than the processor at play here. Such as tact frequency and width of various system buses, hard disks and what not.

The last time I was really interested in PC performance (as opposed to an HPUX Superdome) a Pentium-100 was generally only about 10% slower than a Pentium-200 for most real-life applications.

···

--
Best regards,

Alexey Verkhovsky

Ruby Forum: http://ruby-forum.org (moderator)
RForum: http://rforum.andreas-s.net (co-author)
Instiki: http://instiki.org (maintainer)

Gavin Kistner wrote:

But why would a 2GHz G5 not be at least twice as fast as a 1GHz G4?

G5 versus G4 aside, the doubling of the clock rate alone should suffice, no?

Did memory access speed double, too? Bus speed? Things happen outside of the CPU.

Yes. The G5 has a 1ghz bus compared to the G4's 167mhz. The RAM also increased in speed significantly.

···

On Mar 29, 2005, at 7:24 AM, Timothy Hunter wrote:

Gavin Kistner wrote:

But why would a 2GHz G5 not be at least twice as fast as a 1GHz G4?
G5 versus G4 aside, the doubling of the clock rate alone should suffice, no?

Did memory access speed double, too? Bus speed? Things happen outside of the CPU.