[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

jruby pre-beginner's question (or should I use C

progcat

9/18/2007 2:17:00 AM

My understanding is that Jruby is slower than regular ruby. I take
this to mean the Ruby part is. (am I wrong in this assumption?)

Here is my question: Currently 95% of the execution time of my
program is slow due to loading large quantities stock data, and then
processing it (moving averages, etc). The actual part I want to be
in ruby is fairly quick.

I expect to spend 20% of my PROGRAMMING time (in the future) working
with the "back end" (loading data and processing) and 80% figuring out
how to deal with the results. (hopefully ruby or another very high
level language) The math (arrays) and the io is the slow part.

Would I get the advantage of the speed of Java I did the slow code in
Java or is it better to do it in C? It looks like sharing data
between Java and Jruby is trivial compared to C. Is this fast or
does it take a while to translate?

I know the easy aswer is "do it in C" but I think it would be easier
to code in Java,

I have not actually tried this because I don't know Java, but it seems
like if I put a week into it it should not be too tough for what I
want to do. (load data, basic math, etc)

Basically I want help figuring out if I should spend weeks in C doing
the back end or if I would be satisfied with the (benchmark) results
of Java using Jruby and spend the time to learn Java. (which should be
simpler because it is much higher level)

Thanks in advance. I hope I was asking the right questions.
Tom

3 Answers

Bill Kelly

9/18/2007 2:43:00 AM

0


From: <progcat@comcast.net>

> Here is my question: Currently 95% of the execution time of my
> program is slow due to loading large quantities stock data, and then
> processing it (moving averages, etc). The actual part I want to be
> in ruby is fairly quick.

What language is your program currently written in?

> Would I get the advantage of the speed of Java I did the slow code in
> Java or is it better to do it in C? It looks like sharing data
> between Java and Jruby is trivial compared to C. Is this fast or
> does it take a while to translate?
>
> I know the easy aswer is "do it in C" but I think it would be easier
> to code in Java,
>
> I have not actually tried this because I don't know Java, but it seems
> like if I put a week into it it should not be too tough for what I
> want to do. (load data, basic math, etc)
>
> Basically I want help figuring out if I should spend weeks in C doing
> the back end or if I would be satisfied with the (benchmark) results
> of Java using Jruby and spend the time to learn Java. (which should be
> simpler because it is much higher level)

In situations like this I often write a little test code
to simulate the amount of work that roughly simulates the
amount of I/O and/or computational work that needs to be
done.

The I/O speeds are probably going to be roughly similar
regardless of language used.

Java is similar enough to C and C++ that you could probably
easily write a small test program to perform calculations
similar to what you'll need, say, in a loop on a big array,
and see if the speed is acceptable.

Another possibility might be to look into RubyInline:
http://rubyforge.org/projects/r...

You may be able to write all your code in Ruby, then use
RubyInline to replace slow routines with inline C equivalents.


Hope this helps,

Bill




Kevin Williams

9/18/2007 4:46:00 AM

0

unknown wrote:
> My understanding is that Jruby is slower than regular ruby. I take
> this to mean the Ruby part is. (am I wrong in this assumption?)

It seems Jruby (trunk) may be faster than Ruby 1.8.6.
http://headius.blogspot.com/2007/09/jruby-compiler-update-and...
If you're more comfortable in Java, go for it. Choose what you know
best.
--
Posted via http://www.ruby-....

Rick DeNatale

9/18/2007 12:59:00 PM

0

On 9/17/07, progcat@comcast.net <progcat@comcast.net> wrote:
> My understanding is that Jruby is slower than regular ruby. I take
> this to mean the Ruby part is. (am I wrong in this assumption?)
>
> Here is my question: Currently 95% of the execution time of my
> program is slow due to loading large quantities stock data, and then
> processing it (moving averages, etc). The actual part I want to be
> in ruby is fairly quick.

So as I understand it your problem is IO bound.

> I expect to spend 20% of my PROGRAMMING time (in the future) working
> with the "back end" (loading data and processing) and 80% figuring out
> how to deal with the results. (hopefully ruby or another very high
> level language) The math (arrays) and the io is the slow part.
>
> Would I get the advantage of the speed of Java I did the slow code in
> Java or is it better to do it in C? It looks like sharing data
> between Java and Jruby is trivial compared to C. Is this fast or
> does it take a while to translate?

If most of the overhead is IO then I don't think it makes much
difference, Ruby and Java should be similar, the actual IO is all
being done by C code and the OS anyway.

> I know the easy aswer is "do it in C" but I think it would be easier
> to code in Java,
>
> I have not actually tried this because I don't know Java, but it seems
> like if I put a week into it it should not be too tough for what I
> want to do. (load data, basic math, etc)
>
> Basically I want help figuring out if I should spend weeks in C doing
> the back end or if I would be satisfied with the (benchmark) results
> of Java using Jruby and spend the time to learn Java. (which should be
> simpler because it is much higher level)
>
> Thanks in advance. I hope I was asking the right questions.
> Tom

It sounds like you are at the point where you are learning Ruby, and
thinking ahead of time that you will also need to be learning either
Java or C. If this is the case, I'd recommend that defer the second
question, and focus on learning Ruby well first.

My advice is write it in Ruby, benchmark it, THEN if it's needed work
on optimization. If you start out with pure ruby code you can also
benchmark it using the standard ruby implementation (a.k.a. MRI),
JRuby, maybe Rubinius, or IronRuby as your platform and the maturity
of the alternative implementations allow.

The optimization would go along the lines of:

1) See if refactoring the ruby code can help.
2) When 1 has been exhausted then look at non-ruby extensions,
you've got several options
here.
a) On MRI you can use ruby-inline to easily incorporate
reasonable amounts of C code, or
you can write C extensions.
b) On Jruby you can extend with Java

As far as extending with Java vs. C. If the bottleneck really is IO, I
wouldn't expect a Java extension would really provide much leverage
over ruby code, since for IO ruby and java should be roughly equal.
If you're having to optimize at the basic IO level, the code is all
going to look pretty C like whatever language you use.

But that's just my 2 cents.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...