How fast does your Ruby run?

  • Thread starter SpringFlowers AutumnMoon
  • Start date
J

jzakiya

--------------------------------------------------
n = 1_000_000

start_time = Time.now

for i in 1..n
t = (1..10).inject {|x, y| x + y }
end

run_time = start_time - Time.now

p t

puts
print "Ruby ", RUBY_VERSION, " patch ", RUBY_PATCHLEVEL, " on ",
RUBY_PLATFORM

puts
print "It took #{runt_time} seconds to run."
print " #{(n / run-time).to_i} iterations per
second.\n"
--

opps
print "It took #{run_time} seconds to run."
 
S

Summercool

today, on the Mac OS X 10.5 Leopard


Ruby 1.8.6 patch 36 on universal-darwin9.0
It took 12.960213 seconds to run. 77159 iterations per second.

on the Mac mini
2.0 GHz Core 2 Duo
 
A

ara.t.howard

How fast does your Ruby run?

I got 53648 iterations per second running the following program,
on an Intel 3.2 GHz HT, Win XP machine:

--------

C:\> ruby calculate.rb
55

Ruby 1.8.6 patch 0 on i386-mswin32
It took 18.64 seconds to run. 53648 iterations per second.

--------

n = 1_000_000

start_time = Time.now

for i in 1..n
t = (1..10).inject {|x, y| x + y }
end

finish_time = Time.now

p t

puts
print "Ruby ", RUBY_VERSION, " patch ", RUBY_PATCHLEVEL, " on ",
RUBY_PLATFORM

puts
print "It took #{finish_time - start_time} seconds to run."
print " #{(n / (finish_time - start_time)).to_i} iterations per
second.\n"



cfp:~ > cat a.rb
require 'narray'

n = 1_000_000
t = nil

start_time = Time.now

n.times{ t = NArray.int(10).indgen!(1).sum }

finish_time = Time.now

p t

puts
print "Ruby ", RUBY_VERSION, " patch ", RUBY_PATCHLEVEL, " on ",
RUBY_PLATFORM

puts
print "It took #{finish_time - start_time} seconds to run."
print " #{(n / (finish_time - start_time)).to_i} iterations per
second.\n"


cfp:~ > ruby a.rb
55


2GHz osx

Ruby 1.8.6 patch 0 on i686-darwin8.9.1
It took 2.893815 seconds to run. 345564 iterations per second.



a @ http://codeforpeople.com/
 
S

Summercool

today, on the Mac OS X 10.5 Leopard

Ruby 1.8.6 patch 36 on universal-darwin9.0
It took 12.960213 seconds to run. 77159 iterations per second.

on the Mac mini
2.0 GHz Core 2 Duo

sorry it should have been 82,000 iterations per second. there was an
iChat hogging the CPU for some reason...

on the 2.4GHz Macbook Pro, I got 999,860 iterations per second.
 
G

Greg Halsey

windows xp. intel core2 1.86GHz

JRUBY:

C:\jruby\jruby-trunk\bin>jruby calculate.rb
55

It took 41.125 seconds to run. 24316 iterations per
second.

Not so good. Let's disable ObjectSpace:
C:\jruby\jruby-trunk\bin>jruby -O calculate.rb
55

It took 11.109 seconds to run. 90017 iterations per
second.

That was good. Now let's give it some more juice:
C:\jruby\jruby-trunk\bin>jruby -J-server -O calculate.rb
55

It took 5.75 seconds to run. 173913 iterations per
second.
--------------------------------------------
MRI:One-Click
ruby calculate.rb
55

Ruby 1.8.6 patch 0 on i386-mswin32
It took 15.828 seconds to run. 63179 iterations per
second.
 
D

Daniel Schömer

Gentoo Linux on Intel Pentium 4 2.40GHz (512 KB cache):

Ruby Patch Platform Seconds Iterations per second
===== ===== =================== ========= =====================
1.8.6 111 i686-linux (gentoo) 32.801483 30486
1.8.6 5000 i686-linux 13.607635 73488
1.9.0 0 i686-linux 3.988949 250692
1.8.5 3876 java 63.589 15725
1.8.5 3876 java (-J-server) 44.173 22638
1.8.5 3876 java (-O) 36.917 27087
1.8.5 3876 java (-O -J-server) 15.194 65815

The first is the system installed ruby. The others are current
svn checkouts.

Regards,
Daniel
 
L

Lionel Bouton

Daniel said:
Gentoo Linux on Intel Pentium 4 2.40GHz (512 KB cache):

Ruby Patch Platform Seconds Iterations per second
===== ===== =================== ========= =====================
1.8.6 111 i686-linux (gentoo) 32.801483 30486
1.8.6 5000 i686-linux 13.607635 73488
1.9.0 0 i686-linux 3.988949 250692
1.8.5 3876 java 63.589 15725
1.8.5 3876 java (-J-server) 44.173 22638
1.8.5 3876 java (-O) 36.917 27087
1.8.5 3876 java (-O -J-server) 15.194 65815

The first is the system installed ruby.

IIRC on my Gentoo I got +80% on this particular benchmark with
USE="-threads". Given this huge difference I looked at the speedup for
the test suite of one of my Rails applications and got only ~ +10%.

That said I use Xpath in one Ruby script and the speedup was
unbelievable : maybe +1000% (yes 3 zeros, the script took more than a
minute, maybe several and with USE="-threads" it went through the data
in less than ten seconds).
I believe Ruby compiled with pthread is known to have performance
problems (at least on Linux as I've seen reports of such behavior on
Linux before)...

If you want speed on Linux (and maybe other flavours of Unix), you
should look at compiling it without pthread. Warning: as some classes
may use system libs that *are* compiled with pthread, you might not have
this choice (IIRC the pthread support is there just to support such
libraries).

If someone knows more about this subject (and how to tell if compiling
without pthread is safe), I'd love to know the details.

Regards,

Lionel
 
C

Charles Oliver Nutter

Charles said:
MacBook Pro 2.1G. I tried both Ruby and JRuby.

JRuby:

Ruby 1.8.5 patch 3876 on java
It took 8.022 seconds to run. 124657 iterations per second.

Ruby:

Ruby 1.8.6 patch 0 on i686-darwin8.9.1
It took 10.262067 seconds to run. 97446 iterations per second.

Updated for current JRuby trunk:

JRuby:

Ruby 1.8.5 patch 3876 on java
It took 7.237 seconds to run. 138178 iterations per second.

If I make it run a bit longer, the disparity is greater:

n = 10_000_000

JRuby:

Ruby 1.8.5 patch 3876 on java
It took 61.918 seconds to run. 161503 iterations per second.

Ruby:

Ruby 1.8.6 patch 0 on i686-darwin8.9.1
It took 107.181442 seconds to run. 93299 iterations per second.

- Charlie
 
C

Charles Oliver Nutter

Daniel said:
Gentoo Linux on Intel Pentium 4 2.40GHz (512 KB cache):

Ruby Patch Platform Seconds Iterations per second
===== ===== =================== ========= =====================
1.8.6 111 i686-linux (gentoo) 32.801483 30486
1.8.6 5000 i686-linux 13.607635 73488
1.9.0 0 i686-linux 3.988949 250692
1.8.5 3876 java 63.589 15725
1.8.5 3876 java (-J-server) 44.173 22638
1.8.5 3876 java (-O) 36.917 27087
1.8.5 3876 java (-O -J-server) 15.194 65815

FYI, we're debating making ObjectSpace something you must turn *on* at
command line or through a library call, rather than something you have
to turn off. Practically nothing uses it, and it's a huge perf hit for
JRuby.

Thoughts?

- Charlie
 
M

M. Edward (Ed) Borasky

Charles said:
FYI, we're debating making ObjectSpace something you must turn *on* at
command line or through a library call, rather than something you have
to turn off. Practically nothing uses it, and it's a huge perf hit for
JRuby.

Thoughts?

- Charlie
Just a question -- assuming it's off by default, how do you know when
you need to turn it on?
 
M

M. Edward (Ed) Borasky

Lionel said:
IIRC on my Gentoo I got +80% on this particular benchmark with
USE="-threads". Given this huge difference I looked at the speedup for
the test suite of one of my Rails applications and got only ~ +10%.

That said I use Xpath in one Ruby script and the speedup was
unbelievable : maybe +1000% (yes 3 zeros, the script took more than a
minute, maybe several and with USE="-threads" it went through the data
in less than ten seconds).
I believe Ruby compiled with pthread is known to have performance
problems (at least on Linux as I've seen reports of such behavior on
Linux before)...

If you want speed on Linux (and maybe other flavours of Unix), you
should look at compiling it without pthread. Warning: as some classes
may use system libs that *are* compiled with pthread, you might not have
this choice (IIRC the pthread support is there just to support such
libraries).

If someone knows more about this subject (and how to tell if compiling
without pthread is safe), I'd love to know the details.

Regards,

Lionel

Well, on Gentoo you'd need to turn off the "threads" USE flag globally.
Either everything (in this case Ruby and Tcl/Tk for sure) is with
"threads" or everything is without it. Personally, on my two UP systems
(non-SMP) I turn it off and on my dual-core SMP system I turn it on. But
that's really superstition more than anything based on measurements.

I can't speak for other distros, Windows, Intel vs. AMD, etc. But as far
as I know on Gentoo it's safe to go "-threads" across the board even on
an SMP system. I'm going to go ahead and turn it off on the dual-core
and see what happens -- I'm wrapping up some benchmarking tests this
weekend so it's a good time to play around with it in a controlled
environment.
 
M

M. Edward (Ed) Borasky

Daniel said:
Gentoo Linux on Intel Pentium 4 2.40GHz (512 KB cache):

Ruby Patch Platform Seconds Iterations per second
===== ===== =================== ========= =====================
1.8.6 111 i686-linux (gentoo) 32.801483 30486
1.8.6 5000 i686-linux 13.607635 73488
1.9.0 0 i686-linux 3.988949 250692
1.8.5 3876 java 63.589 15725
1.8.5 3876 java (-J-server) 44.173 22638
1.8.5 3876 java (-O) 36.917 27087
1.8.5 3876 java (-O -J-server) 15.194 65815

The first is the system installed ruby. The others are current
svn checkouts.

Regards,
Daniel

What is "patch 5000"??
 
C

Charles Oliver Nutter

M. Edward (Ed) Borasky said:
Just a question -- assuming it's off by default, how do you know when
you need to turn it on?

We'd print a warning if it's used without being enabled.

- Charlie
 
M

M. Edward (Ed) Borasky

Charles said:
We'd print a warning if it's used without being enabled.

- Charlie
Let me re-phrase that ... how do I know when I'm coding that I'm not
going to ask for it? Do I need to explicitly call/require/include
something to get it?
 
E

Eduardo Tongson

On Gentoo, Ruby with threads is ridiculously slow. Machine is an Xeon
E5320 1.86GHz.

$ ruby-nothreads calculate.rb
55

Ruby 1.8.6 patch 111 on i686-linux
It took 9.759139 seconds to run. 102468 iterations per
second.


$ ruby-threads calculate.rb
55

Ruby 1.8.6 patch 111 on i686-linux
It took 21.473884 seconds to run. 46568 iterations per
second.
 
C

Charles Oliver Nutter

M. Edward (Ed) Borasky said:
Let me re-phrase that ... how do I know when I'm coding that I'm not
going to ask for it? Do I need to explicitly call/require/include
something to get it?

Well, you need to explicitly reference ObjectSpace in most cases to
access it, right?

In general, the tricky bit is that there's at least one key library in
stdlib that depends on ObjectSpace: test/unit, which uses it to locate
tests. However I've implemented in JRuby the ability to walk all child
classes from a parent class, which provides the each_object(Class) used
in test/unit. Currently, you can turn off ObjectSpace support in JRuby
and still have test/unit run.

Raising an error might be a better way to ensure people don't run code
without ObjectSpace enabled, certainly. But maybe they don't care?

It's an open question at the moment, but I don't see that there's any
way ObjectSpace is going to have good performance on these new
implementations where we don't have intimate control over memory and GC.
I expect this is going to be a concern for IronRuby/Ruby.NET too. As far
as I know, JRuby's the only general-purpose VM implementation of Ruby
that's even *attempted* to make ObjectSpace work.

- Charlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top