[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Ruby and an efficiency

Jano Svitok

1/31/2007 2:20:00 PM

On 1/31/07, Miroslaw Maziarz <miroslaw.maziarz@gmail.com> wrote:
> Hi,
> Could anyone tell me or send links where I can find some reliable articles
> about efficiency of ruby.
> How I should coding to keep ruby efficient?
>
> Can I implement c programs in ruby cod?
>
> Greets,
> zirael

General:
http://redhanded.hobix.com/inspect/theFullyUpturn...
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/b1a4bbd4d9ec6246/949cbb0290ac7bef#949cbb...

ruby-prof:
http://on-ruby.blogspot.com/2006/08/profile-and-ruby...
http://on-ruby.blogspot.com/2006/08/profile-and-ruby-prof-getting-spe...
http://on-ruby.blogspot.com/2006/08/ruby-prof-and-call-g...

RubyInline:
http://on-ruby.blogspot.com/2006/07/rubyinline-making-making-things-f...
http://segment7.net/projects/ruby/inline_optimiz...

I guess somewhere on mongrel site (mongrel.rubyforge.org) there is an
article about tuning performance, unfortunately the site is down, so I
cannot check it.

14 Answers

pat eyler

1/31/2007 2:32:00 PM

0

On 1/31/07, Jan Svitok <jan.svitok@gmail.com> wrote:
> RubyInline:
> http://on-ruby.bl.../2006/07/rubyinline-making-making-things-f...

Some people dislike this example because there is so much room for algorithmic
improvement (which I don't dispute). Another example, and one that uses the
Ruby C API from RubyInline is here:

http://on-ruby.bl.../2006/07/rubyinline-going-bit-fu...



> http://segment7.net/projects/ruby/inline_optimiz...
>

You might also find zenspider's posts interesting:

http://blog.zenspider.com/archives/2006/08/writing_c_...

http://blog.zenspider.com/archives/2006/09/recursive_functions_in_rubyi...


> I guess somewhere on mongrel site (mongrel.rubyforge.org) there is an
> article about tuning performance, unfortunately the site is down, so I
> cannot check it.
>
>


--
thanks,
-pate
-------------------------
http://on-ruby.bl...

William James

1/31/2007 8:55:00 PM

0

On Jan 31, 8:31 am, "pat eyler" <pat.ey...@gmail.com> wrote:
> On 1/31/07, Jan Svitok <jan.svi...@gmail.com> wrote:
>
> > RubyInline:
> >http://on-ruby.blogspot.com/2006/07/rubyinline-making-makin......
>
> Some people dislike this example because there is so much room for algorithmic
> improvement (which I don't dispute). Another example, and one that uses the
> Ruby C API from RubyInline is here:
>
> http://on-ruby.blogspot.com/2006/07/rubyinline-going-bit-fu...

This site shows a rather lackluster boost provided by RubyInline.

Let's compare Ruby and Lua.

# A Ruby program based on the one at the link above.
class Array
# build the Array#ravg method in Ruby
def ravg
Float(self.inject {|sum, elem| sum += elem }) /
Float(self.length)
end
end

time = Time.now

# build a good sized loop over a big array
max_loop = (ARGV.shift || 20).to_i
max_size = (ARGV.shift || 1_000_000).to_i
a = (1..max_size).to_a

total = 0
max_loop.times {
total += a.ravg
}
p Time.now - time
p total, total/max_loop

--- Ruby's output -----
151.657
10000010.0
500000.5


-- A Lua program.
function average( list )
local sum = 0
for i = 1, #list do
sum = sum + list[i]
end
return sum / #list
end

local max_loop = 20
local max_size = 1e6

time = os.clock()

local a = {}
for i = 1, max_size do a[i] = i end

local total = 0
for i = 1, max_loop do
total = total + average( a )
end
print( os.clock() - time )
print( total )
print( total/max_loop )

--- output for Lua -----
1.859
10000010
500000.5

--- output for LuaJIT -----
0.891
10000010
500000.5


Based on these results and the ones shown at the link above:

Speed compared to pure Ruby
---------------------------
RubyInline 4.19
Lua 81.57
LuaJIT 170.21

Ara.T.Howard

1/31/2007 9:17:00 PM

0

Ara.T.Howard

1/31/2007 10:14:00 PM

0

Ara.T.Howard

1/31/2007 10:31:00 PM

0

andy

1/31/2007 11:50:00 PM

0


On Jan 31, 2007, at 3:57 PM, Jason Roelofs wrote:

> For performance, use a compiled language?
>
> I like that advice MUCH better.

Ruby IS compiled, just like Perl. It's just done very quickly.

--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance





Devin Mullins

2/1/2007 1:06:00 AM

0

Jan Svitok wrote:
> stuff

Hrm. I was going to add these links to
http://wiki.rubygarden.org/Ruby/page/show/RubyTalkPe..., but it
got shoved into the Tarpit ("Banned URL in content"). Help, anybody?

andy

2/1/2007 1:59:00 PM

0

> Now that's just pushing it. Perl, Ruby, Python, Lua, Squirrel, are all
> WRITTEN in C, but they don't run at C speeds. There's still the
> interpretation overhead...
>
> And Andy? you're also pushing it. Compiled into machine code vs
> compiled
> into an interpreted byte code. You know what is being talked about
> here.

Wow, so angry.

--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance





Paul Brannan

2/1/2007 3:25:00 PM

0

On Thu, Feb 01, 2007 at 08:50:06AM +0900, Andy Lester wrote:
> Ruby IS compiled, just like Perl. It's just done very quickly.

Ruby traverses an AST to evaluate your code. It is not compiled to
machine code.

Paul


andy

2/1/2007 3:27:00 PM

0


On Feb 1, 2007, at 9:24 AM, Paul Brannan wrote:

> On Thu, Feb 01, 2007 at 08:50:06AM +0900, Andy Lester wrote:
>> Ruby IS compiled, just like Perl. It's just done very quickly.
>
> Ruby traverses an AST to evaluate your code. It is not compiled to
> machine code.

I understand that. Close enough for 99% of purposes.

--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance