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-talk/158212
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
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-talk/158212
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
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-talk/158212
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=0321540034
I recommend it highly!
[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 such
as the one posted here:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/158212
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
Vince Forgetta wrote:
Hi all,
Is there some central repository I can get performance tips/discussions
(...)
Thanks.
Vince
Don't use Date objects if you can get by with Time. (As a bonus, if you
start using Time today, you might catch Time.now.to_i == 1234567890)
regards,
Siep
···
--
Posted via http://www.ruby-forum.com/ .
Phil
(Phil)
11 April 2008 04:06
7
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/9780596516178/
- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
~ There's never enough time to do all the nothing you want.
-- Calvin
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-talk/158212
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-forum.com/ .
Robert_K1
(Robert K.)
13 February 2009 08:33
9
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-talk/158212
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.html#M002269
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
···
2008/4/10 Joel VanderWerf <vjoel@path.berkeley.edu >:
--
remember.guy do |as, often| as.you_can - without end
jonty
(jonty)
13 February 2009 23:25
10
Siep Korteling wrote:
Vince Forgetta wrote:
Hi all,
Is there some central repository I can get performance tips/discussions
(...)
Thanks.
Vince
Don't use Date objects if you can get by with Time. (As a bonus, if you start using Time today, you might catch Time.now.to_i == 1234567890)
regards,
Siep
Thanks!!!
I've set up scite with puts Time.now.to_i and am happily pressing f5 every so often watching it creep up to the magic number!
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.rorchina.net
wolf union program club :http://wolf.rorchina.net
China Rubyonrails club: http://bbs.rorchina.net
···
--
Posted via http://www.ruby-forum.com/ .
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/9780596516178/
Thanks a lot, Phillip!!! I will check it out today.
Gennady.
jonty
(jonty)
13 February 2009 23:36
14
jonty wrote:
Siep Korteling wrote:
Vince Forgetta wrote:
Hi all,
Is there some central repository I can get performance tips/discussions
(...)
Thanks.
Vince
Don't use Date objects if you can get by with Time. (As a bonus, if you start using Time today, you might catch Time.now.to_i == 1234567890)
regards,
Siep
Thanks!!!
I've set up scite with puts Time.now.to_i and am happily pressing f5 every so often watching it creep up to the magic number!
I did it! 1234567890! Am I sad or what!
···
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.0.237 / Virus Database: 270.10.23/1951 - Release Date: 02/13/09 06:51:00