[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

performance tips

Vince Forgetta

4/10/2008 8:31:00 PM

[Note: parts of this message were removed to make it a legal post.]

Hi all,

I've been using ruby for about 2 years, but only recently got around trying
and learning it well.

Is there some central repository I can get performance tips/discussions such
as the one posted here:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

These types of tips are saving my bacon!

I'm reading through Matz's new book as well ... what a difference this book
has made!

Thanks.

Vince

13 Answers

Joel VanderWerf

4/10/2008 8:44:00 PM

0

Vince Forgetta wrote:
> Hi all,
>
> I've been using ruby for about 2 years, but only recently got around trying
> and learning it well.
>
> Is there some central repository I can get performance tips/discussions such
> as the one posted here:
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

Instead of:

lines = File.readlines('sometextfile').each {|l| l.chomp!}

do this:

lines = File.open "test" do |f|
f.map {|line| line.chomp}
end

That saves you from having the large string returned by #readlines.

Sorry, no idea if these tips are collected somewhere. The rubygarden
wiki used to have them, IIRC, but it got killed by spam.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

M. Edward (Ed) Borasky

4/11/2008 2:06:00 AM

0

Vince Forgetta wrote:
> Hi all,
>
> I've been using ruby for about 2 years, but only recently got around trying
> and learning it well.
>
> Is there some central repository I can get performance tips/discussions such
> as the one posted here:
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
>
> These types of tips are saving my bacon!
>
> I'm reading through Matz's new book as well ... what a difference this book
> has made!
>
> Thanks.
>
> Vince
>

Well, there's actually a book on the subject ...

http://www.informit.com/store/product.aspx?isbn=...

I recommend it highly!

Vince Forgetta

4/11/2008 3:13:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

perfect! Thanks.

Vince

On Thu, Apr 10, 2008 at 10:05 PM, M. Edward (Ed) Borasky <znmeb@cesmail.net>
wrote:

> Vince Forgetta wrote:
>
> > Hi all,
> >
> > I've been using ruby for about 2 years, but only recently got around
> > trying
> > and learning it well.
> >
> > Is there some central repository I can get performance tips/discussions
> > such
> > as the one posted here:
> >
> > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
> >
> > These types of tips are saving my bacon!
> >
> > I'm reading through Matz's new book as well ... what a difference this
> > book
> > has made!
> >
> > Thanks.
> >
> > Vince
> >
> >
> Well, there's actually a book on the subject ...
>
> http://www.informit.com/store/product.aspx?isbn=...
>
> I recommend it highly!
>
>

Agile Laurel

4/11/2008 3:45:00 AM

0

Vince Forgetta wrote:
> perfect! Thanks.
>
> Vince
>
> On Thu, Apr 10, 2008 at 10:05 PM, M. Edward (Ed) Borasky
> <znmeb@cesmail.net>

up







visit a rubyonrails website :http://www.ro...
wolf union program club :http://wolf.ro...
China Rubyonrails club: http://bbs.ro...

--
Posted via http://www.ruby-....

Gennady Bystritsky

4/11/2008 4:00:00 AM

0

[Sorry for the top-posting, freaking web-mail interface does not do quoting=
properly]

Can you elaborate on what Matz's new book you referring to in your post? I =
could not find anything by Matz in English other than "Ruby in a Nutshell".

Gennady.
________________________________________
From: Vince Forgetta [forgetta@gmail.com]
Sent: Thursday, April 10, 2008 1:30 PM
To: ruby-talk ML
Subject: performance tips

Hi all,

I've been using ruby for about 2 years, but only recently got around trying
and learning it well.

Is there some central repository I can get performance tips/discussions suc=
h
as the one posted here:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

These types of tips are saving my bacon!

I'm reading through Matz's new book as well ... what a difference this book
has made!

Thanks.

Vince

Phillip Gawlowski

4/11/2008 4:06:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gennady Bystritsky wrote:
| [Sorry for the top-posting, freaking web-mail interface does not do
quoting properly]
|
| Can you elaborate on what Matz's new book you referring to in your
post? I could not find anything by Matz in English other than "Ruby in a
Nutshell".

The Ruby Programming Language by O'Reilly. And technically, Matz is the
co-author, not the sole author of the book.

See also: http://www.oreilly.com/catalog/9780...


- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

~ There's never enough time to do all the nothing you want.
-- Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail....

iEYEARECAAYFAkf+47wACgkQbtAgaoJTgL9LmwCfShQaZKNzXljKKRXj2toDfBN0
axAAoKjcWX/07xNntg4jh8jIAeo7kX8t
=QTYm
-----END PGP SIGNATURE-----

Gennady Bystritsky

4/11/2008 5:23:00 PM

0

Phillip Gawlowski wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Gennady Bystritsky wrote:
>> [Sorry for the top-posting, freaking web-mail interface does not do
>> quoting properly]
>>
>> Can you elaborate on what Matz's new book you referring to in your
> post? I could not find anything by Matz in English other than "Ruby
> in a Nutshell".
>
> The Ruby Programming Language by O'Reilly. And technically, Matz is
> the co-author, not the sole author of the book.
>
> See also: http://www.oreilly.com/catalog/9780...
>

Thanks a lot, Phillip!!! I will check it out today.

Gennady.

Maran Chandrasekar

2/13/2009 7:20:00 AM

0

Joel VanderWerf wrote:
> Vince Forgetta wrote:
>> Hi all,
>>
>> I've been using ruby for about 2 years, but only recently got around trying
>> and learning it well.
>>
>> Is there some central repository I can get performance tips/discussions such
>> as the one posted here:
>>
>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
>
> Instead of:
>
> lines = File.readlines('sometextfile').each {|l| l.chomp!}

require 'benchmark'
include Benchmark

bm(7){|test|
test.report('report : '){
lines = File.readlines('LOG/development.log').each {|l|
l.chomp!}
}
}

Output:
user system total real
report : 0.090000 0.030000 0.120000 ( 0.117250)

Actually 'development.log' file 6MB size

> do this:
>
> lines = File.open "test" do |f|
> f.map {|line| line.chomp}
>end


require 'benchmark'
include Benchmark
bm(7){|test|
test.report('report : '){
lines = File.open "LOG/development.log" do |f|
f.map {|line| line.chomp}
end
}
}
Output :
user system total real
report : 0.240000 0.040000 0.280000 ( 0.272991)

which is better?
>
>
> That saves you from having the large string returned by #readlines.
>
> Sorry, no idea if these tips are collected somewhere. The rubygarden
> wiki used to have them, IIRC, but it got killed by spam.


--
Posted via http://www.ruby-....

Robert Klemme

2/13/2009 8:34:00 AM

0

2008/4/10 Joel VanderWerf <vjoel@path.berkeley.edu>:
> Vince Forgetta wrote:
>>
>> Hi all,
>>
>> I've been using ruby for about 2 years, but only recently got around
>> trying
>> and learning it well.
>>
>> Is there some central repository I can get performance tips/discussions
>> such
>> as the one posted here:
>>
>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
>
> Instead of:
>
> lines = File.readlines('sometextfile').each {|l| l.chomp!}
>
> do this:
>
> lines = File.open "test" do |f|
> f.map {|line| line.chomp}
> end
>
> That saves you from having the large string returned by #readlines.

??? I could have understood if you argued that your solution avoids
traversing lines twice but this statement is plain wrong:
File.readlines never returned a single String.

http://www.ruby-doc.org/core/classes/IO.ht...

> Sorry, no idea if these tips are collected somewhere. The rubygarden wiki
> used to have them, IIRC, but it got killed by spam.

Many performance considerations can be found here. Searching for
"Benchmark" should get you pretty far. :-)

Apart from that IMHO there are two major rules of performance which
can help eliminate many performance issues:

1. Do not do unnecessary work.

2. Carefully choose object life cycles.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end

Joel VanderWerf

2/13/2009 4:30:00 PM

0

Robert Klemme wrote:
> 2008/4/10 Joel VanderWerf <vjoel@path.berkeley.edu>:
>> Vince Forgetta wrote:
>>> Hi all,
>>>
>>> I've been using ruby for about 2 years, but only recently got around
>>> trying
>>> and learning it well.
>>>
>>> Is there some central repository I can get performance tips/discussions
>>> such
>>> as the one posted here:
>>>
>>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
>> Instead of:
>>
>> lines = File.readlines('sometextfile').each {|l| l.chomp!}
>>
>> do this:
>>
>> lines = File.open "test" do |f|
>> f.map {|line| line.chomp}
>> end
>>
>> That saves you from having the large string returned by #readlines.
>
> ??? I could have understood if you argued that your solution avoids
> traversing lines twice but this statement is plain wrong:
> File.readlines never returned a single String.

Oops, I think possibly I meant File.read and map:

lines = File.read('sometextfile').map {|l| l.chomp!}

Thanks to you, Robert, and to Tom Link for pointing that out as well in
an email.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407