Hi,
I have snippet from my project, and this iteration is performing very
very badly compared to same implementation in Java
Java : Time Elapsed in milliseconds: 8109 ms.
Ruby : Time Elapsed in Seconds: 132.28125 sec.
It a huge difference, Am i missing something here, is there any
particular best practices.
Yes that's a huge difference, and what you're seeing is roughly what you have to expect. Count on 10-20 times slower unless you are heavily reliant on stuff Java can't do well (like start up times, or fall back on underlying C code as some gems do). Ruby can also be a big help if you have memory constraints.
You might consider JRuby because it sounds as though the JVM is something you're familiar with, but also because you can take advantage of multi-core architectures if your algorithms are parallelisable. But it's a trade off in that some gems won't work in JRuby.
You might also consider coding parts of your program in C. Yeah, I know. This is probably the *last* thing you want to do
I am trying to implement Ruby for a
particular project, where it needs to read/process huge arrays etc
Please guide me.
In general there's not much more to say. But if you get into specifics, maybe. However, most of the suggestions we could make will apply to a Java version as well, so you aren't necessarily going to see a relative performance increase, maybe, if lucky an absolute performance increase.
input = "ababaa" * 10000
suffix_array = input.split(//)
Is that really what you mean?
suffix_array_len = suffix_array.size
for i in 1..suffix_array_len-1 do
Are you starting at 1 for a reason? The first index is 0.
I'd probably write this something like:
(0...l).each do | i |
The '0...l' is the same as 0..(l-1)
total=0
for j in i..suffix_array_len-1 do
end
end
Cheers,
Bob
···
On 2012-06-29, at 1:13 PM, anaray anaray wrote:
--
Posted via http://www.ruby-forum.com/\.
----
Bob Hutchison
Recursive Design Inc.
http://www.recursive.ca/
weblog: http://xampl.com/so